Disable an OCS User using VBscript

One of our readers just asked us how to to disable a user's OCS access using a VBscript.  No problem, here's how.  I haven't done much with VBscript lately, let me blow the dust off my VBscript folder...

user="myUser"
'build an ADO connection to Active Directory
set dse = GetObject("LDAP://RootDSE")
root = dse.Get("RootDomainNamingContext")
adpath = "GC://" & root
base = "<" & adpath & ">"
Set conn = CreateObject("ADODB.Connection")
Set comm = CreateObject("ADODB.Command")
conn.Provider = "ADsDSOObject"
conn.Open "Active Directory Provider"
Set comm.ActiveConnection = conn
comm.Properties("Page Size") = 1000
'search for the user
comm.CommandText = base & ";(&(objectCategory=User)((cn=" & user & ")(sAMAccountName=" & user &")));displayName,distinguishedName;subtree"
Set rs = comm.Execute
Do Until rs.EOF
 displayName = rs.Fields(0).Value
 dn = rs.Fields(1).Value
 Set userObj = GetObject("LDAP://" & dn)
 Wscript.Echo "Disabling " & userObj.givenName & " " & userObj.sn & " for OCS"
'set the OCS properties of the user
 userObj.Put "msRTCSIP-UserEnabled", FALSE
 userObj.SetInfo
rs.MoveNext
Loop

For more OCS scripts, checkout our OCS Script Repository

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...