1

Active Directory: Vbscript to disable Outlook Mobile Access (oma) for all users in your company

Posted March 31st, 2010 in outlookmobileaccess and tagged , , , , , , , , by dirk adamsky

This script disables outlook mobile access for all users in your company, this can be useful when oma access has to be restricted to a certain amount of users. Later I will post a script to enable oma for a limited amount of users based on an excel sheet with smtp addresses.
The script is created for a win2003/exchange2003 environment.

Follow the next steps to run the script (admin rights needed):

* open your favorite text editor
* copy and paste the script into the editor
* save the script (for example c:tempdisableoma.vbs)
* open a command prompt
* go to “c:temp”
* give “cscript disableoma.vbs” (without quotes) and enter

The script:

' Name : disableoma.vbs
' Description : script to disable Outlook Mobile Access (oma) for all users in your company
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 31-03-2010
' Level : intermediate

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)(mail=*)(!(msExchOmaAdminWirelessEnable=7)))"
strAttributes = "mail,distinguishedName"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	Set objUser = GetObject ("LDAP://" & adoRecordset.Fields("distinguishedName").Value)
	objUser.Put "msExchOmaAdminWirelessEnable", "7"
    objUser.Setinfo
	Set objUser = Nothing
	Logprint "outlook mobile access is disabled for ; " & adoRecordset.Fields("mail").Value
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

Function LogPrint(Message)
Const ForAppending = 8
strDate = Replace(Date,"/","-")

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = ObjFSO.OpenTextFile(strDate & "-OmaDisabledUsers.csv", ForAppending, True)
    objTextFile.WriteLine Message
    objTextFile.Close
Set objTextFile = Nothing
Set ObjFSO = Nothing
End Function

When you have problems/questions please post a reply, you can also rate the script.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

[adrotate group="2"]


Related Posts:
  • Active Directory: VBscript to enumerate nested Active Directory groups from an Excel sheet
  • Active Directory: VBscript to enumerate the home directories and their sizes of all users in Active Directory
  • Active Directory: VBscript to enumerate the local profile size of all computers and users in Active Directory

  • One Response so far.

    1. EmJaY says:

      Nice script mate, worked like a charm.

      Cheers.

    Leave a Reply