Tcs
2009-04-05 23:28:09 UTC
I've been trying to update our AD with a script. ( We currently run
ws2k3, but our AD came from ws2k. ) At one time, it WAS working. But
along the way...I've managed to break it. The current error is a (
Type Mismatch ) error at the command ( objUser.SetInfo ). Here's my
script:
=====
'Global variables
' Const ADS_OPTION_SECURITY_MASK = 3
' Const ADS_SECURITY_INFO_DACL = 4
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2
Dim oContainer
Dim strUserToUpdate, strUpdateFlag, strScript
Dim strTelNmbr
'Initialize global variables
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<GC://dc=EastPointCity,dc=org>;(objectCategory=User)" & _
";userAccountControl," & _
"department," & _
"description," & _
"sn," & _
"givenName," & _
"displayName," & _
"streetAddress," & _
"physicalDeliveryOfficeName," & _
"title," & _
"mailNickname," & _
"mail," & _
"IpPhone," & _
"telephoneNumber," & _
"mobile," & _
"facsimileTelephoneNumber," & _
"info," & _
"l," & _
"st," & _
"postalCode," & _
"c," & _
"distinguishedName," & _
"ProfilePath," & _
"ScriptPath," & _
"HomeDirectory," & _
"HomeDrive" & _
";subtree"
Set objRecordSet = objCommand.Execute
'Wscript.Echo "Profile Path: " & objUser.ProfilePath
'Wscript.Echo "Script Path: " & objUser.ScriptPath
'Wscript.Echo "Home Directory: " & objUser.HomeDirectory
'Wscript.Echo "Home Drive: " & objUser.HomeDrive
'On Error Resume Next
intCounter = 0
Do Until objRecordset.EOF
strUpdateFlag = "N"
intUAC=objRecordset.Fields("userAccountControl")
If ( intUAC <> 514 And Not ADS_UF_ACCOUNTDISABLE ) Then
If objRecordset.Fields("sn") > Null Or
objRecordset.Fields("sn") > "" Then
If objRecordset.Fields("givenName") > Null Or
objRecordset.Fields("givenName") > "" Then
If objRecordset.Fields("displayName") <> "Cliff Gibson" Then
If objRecordset.Fields("displayName") <> "Hollis Mason"
Then
' If intCounter < 6 Then
Set strUserToUpdate =
objRecordset.Fields("distinguishedName")
' WScript.Echo "strUser....( " & strUserToUpdate & ")"
' WScript.Echo "distName...( " &
objRecordset.Fields("distinguishedName") & ")"
Set objUser = GetObject _
( "LDAP://" &
objRecordset.Fields("distinguishedName") )
' strTelNmbr = objRecordset.Fields("telephoneNumber")
' WScript.Echo "telephoneNumber...(" & strTelNmbr & ")"
' If Len( strTelNmbr ) > 4 Then
' If strTelNmbr > "000" Then
' If strTelNmbr < "10000" Then
' WScript.Echo Right( strTelNmbr, 4 )
' objUser.Put "IpPhone", Right( strTelNmbr, 4 )
' End If
' End If
' End If
If objRecordset.Fields("department") = "Finance (
Accounting )" Then
Call ShowMe
objUser.Put "streetAddress", "1526 E Forrest Ave, Ste
400"
objUser.Put "physicalDeliveryOfficeName", "Accounting"
Call ShowMe
End If
If objRecordset.Fields("department") = "Finance ( Admin
)" Then
Call ShowMe
objUser.Put "streetAddress", "2777 East Point St" &
vbCrLf & "City Hall (3rd Floor)"
objUser.Put "physicalDeliveryOfficeName", "Finance"
Call ShowMe
End If
If objRecordset.Fields("department") = "Property Tax"
Then
Call ShowMe
objUser.Put "streetAddress", "1526 E Forrest Ave, Ste
400"
objUser.Put "physicalDeliveryOfficeName", "Property
Tax"
Call ShowMe
End If
If strUpdateFlag = "Y" Then
objUser.Put "company", "City of East Point"
objUser.Put "l", "East Point"
objUser.Put "st", "Georgia"
objUser.Put "postalCode", "30344"
objUser.Put "c", "United States"
' WScript.Echo "Updating...(" &
objRecordset.Fields("displayName") & ")"
' WScript.Echo _
' "Title..........(" & objRecordset.Fields("title") &
")" & vbCrLf & _
' "Profile Path..(" &
objRecordset.Fields("ProfilePath") & ")" & vbCrLf & _
' "ScriptPath....(" &
objRecordset.Fields("ScriptPath") & ")" & vbCrLf & _
' "HomeDir......(" &
objRecordset.Fields("HomeDirectory") & ")" & vbCrLf & _
' "HomeDrive...(" & objRecordset.Fields("HomeDrive") &
")"
' obj.put "ntsecuritydescriptor",oSD
' obj.SetOption ADS_OPTION_SECURITY_MASK,
ADS_SECURITY_INFO_DACL<BR/>
objUser.SetInfo
' intCounter = intCounter + 1
End If
' End If
End If
End If
End If
End If
End If
objRecordset.MoveNext
Loop
'Clean up
objConnection.Close
Set oContainer = Nothing
WScript.Echo "Updated...(" & intCounter & ")...records."
WScript.Echo "Finished"
WScript.Quit(0)
'+-----------------------------------------------------------------------------+
'| |
'+-----------------------------------------------------------------------------+
Function ShowMe
' intCounter = intCounter + 1
strUpdateFlag = "Y"
WScript.Echo _
"Updating.......(" & objRecordset.Fields("displayName") & ")" &
vbCrLf & vbCrLf & _
"Department.....(" & objRecordset.Fields("department") & ")" &
vbCrLf & _
"LastName.......(" & objRecordset.Fields("sn") & ")" & vbCrLf
& _
"FirstName......(" & objRecordset.Fields("givenName") & ")" &
vbCrLf & _
"DisplayName....(" & objRecordset.Fields("displayName") & ")"
& vbCrLf & _
"StreetAddress..(" & objRecordset.Fields("streetAddress") &
")" & vbCrLf & _
"OfcLocation....(" &
objRecordset.Fields("physicalDeliveryOfficeName") & ")" & vbCrLf & _
"Title..........(" & objRecordset.Fields("title") & ")" &
vbCrLf & _
"EmailAlias.....(" & objRecordset.Fields("mailNickname") & ")"
& vbCrLf & _
"EmailAddr......(" & objRecordset.Fields("mail") & ")" &
vbCrLf & _
"IpPhone........(" & objRecordset.Fields("IpPhone") & ")" &
vbCrLf & _
"TelNumber......(" & objRecordset.Fields("telephoneNumber") &
")" & vbCrLf & _
"Cell...........(" & objRecordset.Fields("mobile") & ")" &
vbCrLf & _
"Fax............(" &
objRecordset.Fields("facsimileTelephoneNumber") & ")" & vbCrLf & _
"'info'.........(" & objRecordset.Fields("info") & ")" &
vbCrLf & _
"City...........(" & objRecordset.Fields("l") & ")" & vbCrLf &
_
"State..........(" & objRecordset.Fields("st") & ")" & vbCrLf
& _
"ZipCode........(" & objRecordset.Fields("postalCode") & ")" &
vbCrLf & _
"Country........(" & objRecordset.Fields("c") & ")" & vbCrLf &
_
"distName.......(" & objRecordset.Fields("distinguishedName")
& ")" & vbCrLf & _
"ProfilePath....(" & objRecordset.Fields("ProfilePath") & ")"
& vbCrLf & _
"ScriptPath.....(" & objRecordset.Fields("ScriptPath") & ")" &
vbCrLf & _
"HomeDirectory..(" & objRecordset.Fields("HomeDirectory") &
")" & vbCrLf & _
"HomeDrive......(" & objRecordset.Fields("HomeDrive") & ")"
' For Each strValue in objUser.description
' WScript.Echo "Description..(" & strValue & ")"
' Next
' "Description....(" & objRecordset.Fields("description") & ")"
'objUser.PutEx ADS_PROPERTY_UPDATE, _
' "description", Array("Management staff")
End Function
'
' End of script
'
=====
Also, I can't seem to see the Description. That was generating an
error also, so I unhooked it. The important part is that I can't
update anyone now. I can silence the error by enabling ( On error
resume next ), but it still doesn't update anyone.
Any suggestions/ideas/thoughts would be apreciated.
Thanks a lot,
Tom
ws2k3, but our AD came from ws2k. ) At one time, it WAS working. But
along the way...I've managed to break it. The current error is a (
Type Mismatch ) error at the command ( objUser.SetInfo ). Here's my
script:
=====
'Global variables
' Const ADS_OPTION_SECURITY_MASK = 3
' Const ADS_SECURITY_INFO_DACL = 4
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2
Dim oContainer
Dim strUserToUpdate, strUpdateFlag, strScript
Dim strTelNmbr
'Initialize global variables
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<GC://dc=EastPointCity,dc=org>;(objectCategory=User)" & _
";userAccountControl," & _
"department," & _
"description," & _
"sn," & _
"givenName," & _
"displayName," & _
"streetAddress," & _
"physicalDeliveryOfficeName," & _
"title," & _
"mailNickname," & _
"mail," & _
"IpPhone," & _
"telephoneNumber," & _
"mobile," & _
"facsimileTelephoneNumber," & _
"info," & _
"l," & _
"st," & _
"postalCode," & _
"c," & _
"distinguishedName," & _
"ProfilePath," & _
"ScriptPath," & _
"HomeDirectory," & _
"HomeDrive" & _
";subtree"
Set objRecordSet = objCommand.Execute
'Wscript.Echo "Profile Path: " & objUser.ProfilePath
'Wscript.Echo "Script Path: " & objUser.ScriptPath
'Wscript.Echo "Home Directory: " & objUser.HomeDirectory
'Wscript.Echo "Home Drive: " & objUser.HomeDrive
'On Error Resume Next
intCounter = 0
Do Until objRecordset.EOF
strUpdateFlag = "N"
intUAC=objRecordset.Fields("userAccountControl")
If ( intUAC <> 514 And Not ADS_UF_ACCOUNTDISABLE ) Then
If objRecordset.Fields("sn") > Null Or
objRecordset.Fields("sn") > "" Then
If objRecordset.Fields("givenName") > Null Or
objRecordset.Fields("givenName") > "" Then
If objRecordset.Fields("displayName") <> "Cliff Gibson" Then
If objRecordset.Fields("displayName") <> "Hollis Mason"
Then
' If intCounter < 6 Then
Set strUserToUpdate =
objRecordset.Fields("distinguishedName")
' WScript.Echo "strUser....( " & strUserToUpdate & ")"
' WScript.Echo "distName...( " &
objRecordset.Fields("distinguishedName") & ")"
Set objUser = GetObject _
( "LDAP://" &
objRecordset.Fields("distinguishedName") )
' strTelNmbr = objRecordset.Fields("telephoneNumber")
' WScript.Echo "telephoneNumber...(" & strTelNmbr & ")"
' If Len( strTelNmbr ) > 4 Then
' If strTelNmbr > "000" Then
' If strTelNmbr < "10000" Then
' WScript.Echo Right( strTelNmbr, 4 )
' objUser.Put "IpPhone", Right( strTelNmbr, 4 )
' End If
' End If
' End If
If objRecordset.Fields("department") = "Finance (
Accounting )" Then
Call ShowMe
objUser.Put "streetAddress", "1526 E Forrest Ave, Ste
400"
objUser.Put "physicalDeliveryOfficeName", "Accounting"
Call ShowMe
End If
If objRecordset.Fields("department") = "Finance ( Admin
)" Then
Call ShowMe
objUser.Put "streetAddress", "2777 East Point St" &
vbCrLf & "City Hall (3rd Floor)"
objUser.Put "physicalDeliveryOfficeName", "Finance"
Call ShowMe
End If
If objRecordset.Fields("department") = "Property Tax"
Then
Call ShowMe
objUser.Put "streetAddress", "1526 E Forrest Ave, Ste
400"
objUser.Put "physicalDeliveryOfficeName", "Property
Tax"
Call ShowMe
End If
If strUpdateFlag = "Y" Then
objUser.Put "company", "City of East Point"
objUser.Put "l", "East Point"
objUser.Put "st", "Georgia"
objUser.Put "postalCode", "30344"
objUser.Put "c", "United States"
' WScript.Echo "Updating...(" &
objRecordset.Fields("displayName") & ")"
' WScript.Echo _
' "Title..........(" & objRecordset.Fields("title") &
")" & vbCrLf & _
' "Profile Path..(" &
objRecordset.Fields("ProfilePath") & ")" & vbCrLf & _
' "ScriptPath....(" &
objRecordset.Fields("ScriptPath") & ")" & vbCrLf & _
' "HomeDir......(" &
objRecordset.Fields("HomeDirectory") & ")" & vbCrLf & _
' "HomeDrive...(" & objRecordset.Fields("HomeDrive") &
")"
' obj.put "ntsecuritydescriptor",oSD
' obj.SetOption ADS_OPTION_SECURITY_MASK,
ADS_SECURITY_INFO_DACL<BR/>
objUser.SetInfo
' intCounter = intCounter + 1
End If
' End If
End If
End If
End If
End If
End If
objRecordset.MoveNext
Loop
'Clean up
objConnection.Close
Set oContainer = Nothing
WScript.Echo "Updated...(" & intCounter & ")...records."
WScript.Echo "Finished"
WScript.Quit(0)
'+-----------------------------------------------------------------------------+
'| |
'+-----------------------------------------------------------------------------+
Function ShowMe
' intCounter = intCounter + 1
strUpdateFlag = "Y"
WScript.Echo _
"Updating.......(" & objRecordset.Fields("displayName") & ")" &
vbCrLf & vbCrLf & _
"Department.....(" & objRecordset.Fields("department") & ")" &
vbCrLf & _
"LastName.......(" & objRecordset.Fields("sn") & ")" & vbCrLf
& _
"FirstName......(" & objRecordset.Fields("givenName") & ")" &
vbCrLf & _
"DisplayName....(" & objRecordset.Fields("displayName") & ")"
& vbCrLf & _
"StreetAddress..(" & objRecordset.Fields("streetAddress") &
")" & vbCrLf & _
"OfcLocation....(" &
objRecordset.Fields("physicalDeliveryOfficeName") & ")" & vbCrLf & _
"Title..........(" & objRecordset.Fields("title") & ")" &
vbCrLf & _
"EmailAlias.....(" & objRecordset.Fields("mailNickname") & ")"
& vbCrLf & _
"EmailAddr......(" & objRecordset.Fields("mail") & ")" &
vbCrLf & _
"IpPhone........(" & objRecordset.Fields("IpPhone") & ")" &
vbCrLf & _
"TelNumber......(" & objRecordset.Fields("telephoneNumber") &
")" & vbCrLf & _
"Cell...........(" & objRecordset.Fields("mobile") & ")" &
vbCrLf & _
"Fax............(" &
objRecordset.Fields("facsimileTelephoneNumber") & ")" & vbCrLf & _
"'info'.........(" & objRecordset.Fields("info") & ")" &
vbCrLf & _
"City...........(" & objRecordset.Fields("l") & ")" & vbCrLf &
_
"State..........(" & objRecordset.Fields("st") & ")" & vbCrLf
& _
"ZipCode........(" & objRecordset.Fields("postalCode") & ")" &
vbCrLf & _
"Country........(" & objRecordset.Fields("c") & ")" & vbCrLf &
_
"distName.......(" & objRecordset.Fields("distinguishedName")
& ")" & vbCrLf & _
"ProfilePath....(" & objRecordset.Fields("ProfilePath") & ")"
& vbCrLf & _
"ScriptPath.....(" & objRecordset.Fields("ScriptPath") & ")" &
vbCrLf & _
"HomeDirectory..(" & objRecordset.Fields("HomeDirectory") &
")" & vbCrLf & _
"HomeDrive......(" & objRecordset.Fields("HomeDrive") & ")"
' For Each strValue in objUser.description
' WScript.Echo "Description..(" & strValue & ")"
' Next
' "Description....(" & objRecordset.Fields("description") & ")"
'objUser.PutEx ADS_PROPERTY_UPDATE, _
' "description", Array("Management staff")
End Function
'
' End of script
'
=====
Also, I can't seem to see the Description. That was generating an
error also, so I unhooked it. The important part is that I can't
update anyone now. I can silence the error by enabling ( On error
resume next ), but it still doesn't update anyone.
Any suggestions/ideas/thoughts would be apreciated.
Thanks a lot,
Tom