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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find roaming profile users 1

Status
Not open for further replies.

puppet

IS-IT--Management
Dec 13, 2001
140
Is there any way to search AD to find (and create a list of) users that have roaming profiles setup? I have very little scripting experience.

Thanks
 
Here is the basic script that will return the information you are looking for. You only need to edit it to hot al users rather than the hard coded single user.

Take a look at the FAQs section of this forum for help on making scripts enterprise ready.

Code:
On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strProfilePath = objUser.Get("profilePath")
strScriptPath = objUser.Get("scriptPath")
strHomeDirectory = objUser.Get("homeDirectory")
strHomeDrive = objUser.Get("homeDrive")

WScript.echo "profilePath: " & strProfilePath
WScript.echo "scriptPath: " & strScriptPath
WScript.echo "homeDirectory: " & strHomeDirectory
WScript.echo "homeDrive: " & strHomeDrive

I hope you find this post helpful.

Regards,

Mark
 
Ok I've had a bit of a go with the following script from the FAQ section and changed the "computer" to "profilepath" thinking this might give me the profile paths of all the users in the domain rather than the computer name of all the computers in the domain but what I get is a list of all users, groups and computers! Any help would be greatly appreciated as I really don't know what I am doing here!

Thanks



Dim objIADsContainer ' ActiveDs.IADsDomain - ' Container object
Dim objIADsComputer ' ActiveDs.IADsComputer
Dim Partition, Partitions
Set Partitions = GetObject("LDAP://CN=Partitions,CN=Configuration," & _
GetObject("LDAP://RootDSE").Get("DefaultNamingContext"))
On Error Resume Next
For Each Partition In Partitions
strDomain = Partition.Get("nETBIOSName")
If Err.Number = 0 then Exit For
Next
Set Partitions = Nothing


' connect to the computer.
Set objIADsContainer = GetObject("WinNT://" & strDomain)

' set the filter to retrieve only objects of class Computer
objIADsContainer.Filter = Array("computer")


For Each objIADsComputer In objIADsContainer
report = report & objIADsComputer.Name & vbCrLf
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("wslist.txt", ForWriting)
ts.write report


Set fso = Nothing
Set objIADsComputer = Nothing
Set objIADsContainer = Nothing


MsgBox "Done"
 
This will list the users and there profile path out to a csv text file. Don't forget to replace "YourDomainHere" with your domain.

Set fso = CreateObject("Scripting.FileSystemObject")
set txtStream = fso_OpenTextFile("UserProfileList.csv", 2, True)
txtStream.WriteLine "Begin : " & date & " " & Time

Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI
objCommandADSI.Properties("Size Limit")= 10000
objCommandADSI.Properties("Page Size")= 10000
objCommandADSI.CommandText = "<LDAP://YOurDomainHere>;(objectClass=user);" & _
"sAMAccountName," & _
"name," & _
"profilePath;subtree"
Set objRSADSI = objCommandADSI.Execute
do while NOT objRSADSI.EOF
if len(objRSADSI.fields("profilePath")) > 0 then
txtStream.WriteLine objRSADSI.fields("name") & "," & _
objRSADSI.fields("sAMAccountName") & "," & _
objRSADSI.fields("profilePath")
end if
objRSADSI.MoveNext
loop
txtStream.WriteLine "End : " & date & " " & Time
wscript.echo "Done!"

Good luck and I hope this helps.
 
Cool that looks perfect - will this include all users in the domain - regardless of the OU that they are in?
 
Yes. It will also include disabled users, just keep that in mind. It you need to eliminate all disabled users then I can help with that, but some admins delete old users while others make the accounts disabled. Let me know if you would like to filter out the disabled accounts.

Glad I could help.
 
This modification to foster2000's script will run without editing as it will detect the domain information.

Code:
Set objDomain = getObject("LDAP://rootDse")
strDomainNC = objDomain.Get("defaultNamingContext")
ldPath = "<LDAP://" & strDomainNC & ">"

Set fso = CreateObject("Scripting.FileSystemObject")
set txtStream = fso.OpenTextFile("UserProfileList.csv", 2, True)
txtStream.WriteLine "Begin : " & date & " " & Time

Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI
objCommandADSI.Properties("Size Limit")= 10000
objCommandADSI.Properties("Page Size")= 10000
objCommandADSI.CommandText = ldPath & ";(objectClass=user);" & _
                             "sAMAccountName," & _
                             "name," & _
                             "profilePath;subtree"
Set objRSADSI = objCommandADSI.Execute
do while NOT objRSADSI.EOF
   if len(objRSADSI.fields("profilePath")) > 0 then
      txtStream.WriteLine objRSADSI.fields("name") & "," & _
                          objRSADSI.fields("sAMAccountName") & "," & _
                          objRSADSI.fields("profilePath")
   end if
   objRSADSI.MoveNext
loop
txtStream.WriteLine "End : " & date & " " & Time
wscript.echo "Done!"

I hope you find this post helpful.

Regards,

Mark
 
Thanks, I've started doing this to all of my own scripts as I re-use them. Wish i had learned that trick a long time ago. It makes for easier use when going from client to client.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top