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!

Search for User Accounts with profiles on a server 1

Status
Not open for further replies.

MikeBatters

Technical User
Jan 13, 2005
417
GB
I am hoping someone can help becuase i can't find a way of doing this.

I am trying to write a script that will read through all the users in the AD or an OU checking if the ProfilePath or TerminalServicesProfilePath begins with a specific sting (\\servername\) so that i can replace it with a new string (\\server2\).

I have got the script to replace the characters in the fields but i cannot work out how to search in the first place.

My plan was to search and when a user matches the criteria write the username to an array so that i can use the array later in a For Each loop to write the changes back.

Any help with this would be really appreicated and i am not too proud to copy a script that already does all of this if someone has written this already and if feeling kind enough to share.

Thanks in Advance

Mike

*************************************

Remember - There is always another way..........I just haven't found out what it is yet!

[yinyang]
 
Thanks dm.

I have been looking through these examples already to assemble all the update code etc but i cannot find any thing which suggests how to search through all users who's ProfilePath matches a string.

Would you be able to point out a scrupt where this actually exists.....?

Mike

*************************************

Remember - There is always another way..........I just haven't found out what it is yet!

[yinyang]
 
ADO SQL approach can yeild recordsets...

SELECT distinguishedname,samaccountname,extensionattribute3,extensionattribute4 FROM 'LDAP://serverfqdn' WHERE extensionattribute4 LIKE 'FS*' AND extensionattribute3 LIKE 'FS*' ORDERBY extensionattribute4 asc"

adjust to fit you size :)
 
Thanks MrMovie.

Can anyone think of an approach that doesn't need SQL Server?

Mike

*************************************

Remember - There is always another way..........I just haven't found out what it is yet!

[yinyang]
 
sorry, you misunderstand, you dont need an SQL server.

it goes something like this in your script

Set oCommand = CreateObject("ADODB.Command")
'#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

then

oCommand.commandtext = strQuery

where strQuery is your SQL style string, as i posted earlier...

then

Set oRs = oCommand.execute

returns you a record set of all 'things' matching...
 
this is an example someone else posted, sorry i dont have the details of who...you will need to change a lot of it but it will give you the 'bigger picture'

Const ADS_SCOPE_SUBTREE = 2

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

FindUser = InputBox("Please Enter A UserName", "Find User OU")
If FindUser = "" Then
MsgBox("No UserName Was Added")
WScript.Quit
Else
strUser = FindUser
End If

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT distinguishedName FROM 'LDAP://dc=yourdomain,dc=com'WHERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
arrPath = Split(strDN, ",")
intLength = Len(arrPath(1))
intNameLength = intLength - 3
Wscript.Echo "User :" & strUser & Right(arrPath(1), intNameLength)
objRecordSet.MoveNext
Loop
 
Thats the one...Thanks MrMovie

Mike

*************************************

Remember - There is always another way..........I just haven't found out what it is yet!

[yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top