Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wants to change Profile field for all users how ? 1

Status
Not open for further replies.

larsjuhl

IS-IT--Management
Oct 24, 2001
88
DK
I want to reset the PROFILE FIELD on all users in AD, remove the logon script path and the home dir patch all to be left blank.
I suppose I need a script using ADSI to perform the changed can anyone give me something to work with ?
found this on tech-net:

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "givenName", "Ken"
objUser.Put "initials", "E."
objUser.Put "sn", "Myer"
objUser.Put "displayName", "Myer, Ken"
objUser.Put "physicalDeliveryOfficeName", "Room 4358"
objUser.Put "telephoneNumber", "(425) 555-1211"
objUser.Put "mail", "myerken@fabrikam.com"
objUser.Put " "
objUser.PutEx ADS_PROPERTY_UPDATE, _
"description", Array("Management staff")
objUser.PutEx ADS_PROPERTY_UPDATE, _
"otherTelephone", Array("(800) 555-1212", "(425) 555-1213")
objUser.PutEx ADS_PROPERTY_UPDATE, _
"url", Array("
objUser.SetInfo

But I need to reset all users in one OU´s Profile Field and the above script doesnt help me much... I know.
new to this scripting and just need this to be fixed fast, hope someone can help me.

rgds,
Lars
 
now Ive found this :

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "initials", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "otherTelephone", 0

objUser.SetInfo

This does the trick for the genral page initials and othertelephone, I just need help to get it rolling for all users in one ou instead of me having to fill in the user name manually, otherwise i can do it in the mmc ....

please anyone ?
 
'################################################################
'##### GET A RECORDSET BACK FROM ACTIVE DIRECTORY OF THE DNSNODES
'#setup ADODB Command Object, setup ADODB Connection object ####
'################################################################
Set oConnection = CreateObject("ADODB.Connection") '#
oConnection.Provider = "ADsDSOObject" '#
oConnection.Open = "Active Directory Provider" '#
oCommand.ActiveConnection = oConnection '#then Create a connection.
Set oRoot = GetObject("LDAP://RootDSE") '#
oCommand.Properties("Page Size") = 999
sdnsDomain = "dc=fsc,dc=net"
sQuery = "SELECT scriptPath, sAMAccountName FROM 'LDAP://bramd2ka.bra.fsc.net' WHERE objectClass = 'person' AND sAMAccountName='bra*'"
oCommand.commandtext = sQuery 'set the command text
Wscript.Echo Now()
oCommand.Properties("Page Size") = 999 'set the page size to allow for more than a 1000 records
Set oRs = oCommand.execute '"seECT distinguishedname,samaccountname,extensionattribute3,extensionattribute4 FROM 'LDAP://bramd2ka.bra.fsc.net' WHERE extensionattribute4 LIKE 'FS*' AND extensionattribute3 LIKE 'FS*' ORDERBY extensionattribute4 asc")

Wscript.Echo oRS.RecordCount

While Not oRS.EOF
If Right(CStr(oRS.Fields(&quot;sAMAccountName&quot;)), 1) <> &quot;$&quot; Then
If IsNull(oRS.Fields(&quot;scriptPath&quot;)) Then
Wscript.Echo &quot;null &quot; & oRS.Fields(&quot;sAMAccountName&quot;)
Else
If Trim(LCase(CStr(oRS.Fields(&quot;scriptPath&quot;)))) <> &quot;fsc\loginloader.bat&quot; Then
Wscript.Echo oRS.Fields(&quot;scriptPath&quot;) & &quot; &quot; & oRS.Fields(&quot;sAMAccountName&quot;)
End If
End If
End If
oRS.MoveNext
Wend
 
so, get a recordset of your users and loop through checking the attributes you are interested in. when you find one which isnt NULL or &quot;&quot; then do a GetObject on the username and change the attributes you want. move onto the next record.

hope this helps
 
hmm.. mr.movie .. thanks Im way over my head here I see.
I got scared just trying to understand your script.. :eek:)
This script is just a one timer and was hoping for a fast solution seemes like I have to do this manually.

thanks for your help.

Lars
 
sorry, try the below. it will be slower than the other post but easier i guess. i havent tested it but it should work


Set Group = GetObject(&quot;WinNT://&quot; & strDomain & &quot;/&quot; & strGroupName & &quot;,group&quot;)
For Each aMember In Group.Members

strUser = &quot;&quot;
strUser = aMember.Name
Set User = GetObject(&quot;WinNT://&quot; & strDomain & &quot;/&quot; & strUser & &quot;,user&quot;)
User.HomeDirectory = &quot;&quot;
User.LoginScript = &quot;&quot;
User.SetInfo
Set User = Nothing

Next
Set Group = Nothing
 
Thanks guys,
This script did the trick for me.

Const ADS_PROPERTY_CLEAR = 1
Set objOU = GetObject(&quot;LDAP://ou=nameofou,dc=dcname,dc=com&quot;)

objOU.Filter = Array(&quot;user&quot;)

For Each objUser In objOU
objUser.PutEx ADS_PROPERTY_CLEAR, &quot;scriptpath&quot;, 0
objUser.SetInfo
objUser.PutEx ADS_PROPERTY_CLEAR, &quot;homedrive&quot;, 0
objUser.SetInfo
objUser.PutEx ADS_PROPERTY_CLEAR, &quot;homedirectory&quot;, 0
objUser.SetInfo

Next
wscript.echo &quot;finished&quot;

thank you for all your input
Lars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top