Solved

VB Script Help with AD

Posted on 2008-10-09
3
504 Views
Last Modified: 2013-12-24
Please can you help?
I got the following script from Microsoft. It is supposed to disable to OMA for accoutns in AD.

=================================================
On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objUsers = GetObject("LDAP://CN=Users, " & objRootDSE.Get("defaultNamingContext"))
' set msExchOmaAdminWirelessEnable to 7 if currently null
For Each objUser In objUsers
            strname = objUser.Get("name")
'            WScript.Echo "name: " & strname
            strWirelessEnabled = objUser.Get("msExchOmaAdminWirelessEnable")
            If strWirelessEnabled = "" Then
                        objUser.Put "msExchOmaAdminWirelessEnable", "7"
                        objUser.setinfo
            End If
            strWirelessEnabled = objUser.Get("msExchOmaAdminWirelessEnable")          
Next
WScript.Echo "Mobile Services disabled for all users"
===========================================================

The OU where the accounts reside in my AD is:

Enter.local,   Users, London  (ou=London, ou=users, dc=Enter, dc=local)

When I run the script nothing changes. Maybe I havent entered the LDAP path correctly in the query? I noticed in the example from Microsoft that they entered the Users OU as CN=Users and I have also tried to change my script as such and still it doesn't work.

I have edited the script as below:

==================================================
On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objUsers = GetObject("LDAP://OU=London,OU=Users,DC=Enter,DC=local, " & objRootDSE.Get("defaultNamingContext"))
' set msExchOmaAdminWirelessEnable to 7 if currently null
For Each objUser In objUsers
            strname = objUser.Get("name")
'            WScript.Echo "name: " & strname
            strWirelessEnabled = objUser.Get("msExchOmaAdminWirelessEnable")
            If strWirelessEnabled = "" Then
                        objUser.Put "msExchOmaAdminWirelessEnable", "7"
                        objUser.setinfo
            End If
            strWirelessEnabled = objUser.Get("msExchOmaAdminWirelessEnable")          
Next
WScript.Echo "Mobile Services disabled for all users"

Based on the location of the OU, please can someone help me get this script working.

Thanks in advance.



0
Comment
Question by:naifyboy123
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 22684280
Hi, you cannot do:
Set objUsers = GetObject("LDAP://OU=London,OU=Users,DC=Enter,DC=local," & objRootDSE.Get("defaultNamingContext"))

as this would give you
OU=London,OU=Users,DC=Enter,DC=local,DC=Enter,DC=local

try either
Set objUsers = GetObject("LDAP://OU=London,OU=Users,DC=Enter,DC=local"

or
Set objUsers = GetObject("LDAP://OU=London,OU=Users," & objRootDSE.Get("defaultNamingContext"))

The objRootDSE.Get("defaultNamingContext") should automatically return your default naming context of DC=enter,DC=local

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22684519
Thanks for the grade.  I hope I was clear.  Do my comments make sense?

Regards,

Rob.
0
 

Author Comment

by:naifyboy123
ID: 22684533
yes they do thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now