Problem solve Get help with specific problems with your technologies, process and projects.

Can WSH or VBSCRIPT display roaming user profile accounts?

Can I use WSH or VBSCRIPT to display a list of domain user accounts that are configured with Roaming User Profiles?

Can I use WSH or VBSCRIPT to display a list of domain user accounts that are configured with Roaming User Profiles? Contrarily, can I list users not configured as Roaming User Profiles?

Yes and Yes. The following script will enumerate the users, collect information on the home directory locations, last login and profile directories into comma delimited file (.CSV) stored on your desktop. Any user with a NULL profile string will not have a roaming profile.

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")

' -- Your domain name
strDomain = GetDomain()
strDomain = InputBox("This scrip enumerates all 
users and" & vbCRLF &_
 "profile information to a commana delimited file" 
& vbCRLF &_
 vbCRLF & vbCRLF & "Enter the Domain Name","List Users",strDomain)
If strDomain = "" Then
End If

' -- Your known user name
strUser = WshNetwork.UserName ' - all properties are based 
on this user

' -- Create the file on the desktop
fname = WshShell.SpecialFolders("Desktop")& "" & strDomain 
set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists (fname) THEN
 set objFile = fso.GetFile (fname)
End If
set objFile = fso.CreateTextFile (fname, True)

' -- Get the domain object
Set objDomain = GetObject("WinNT://" & strDomain)
objDomain.Filter = Array("user")

' -- Get a known user to get a list of properties
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)
propcount = 3

' -- Write a header line with property names
s = CHR(34) & "Name" & CHR(34) & "," & CHR(34) 
& "LastLogin" 
& CHR(34) & "," & CHR(34) & "HomeDirectory" & CHR(34) 
& "," & CHR(34) & "Profile" & CHR(34) & "," & CHR(34) 
& "Groups" & CHR(34) & ","
Dim aProps()
ReDim aProps(propcount)
objFile.WriteLine s

' -- step through all users and write their properties
For each objUser in objDomain
 s = CHR(34) & objUser.Name & CHR(34) & ","
 For i = 0 To propcount-1
 v = GetProp(aProps(i))
 s = s & CHR(34) & v & CHR(34) & ","
 For Each objGroup In objUser.Groups
 s = s & CHR(34) & objGroup.Name & CHR(34) &","
 'Remove comment to debug WScript.Echo s
 objFile.WriteLine s

Wscript.Echo "File Created: " & fname

Function GetProp(strWhat)
 on error resume next
 strProp = objUser.Get(strWhat)
' If IsNull(strProp) or IsEmpty(strProp) Then
' GetProp = "UA"
' Else
 If varType(strProp) = 8209 Then ' login hours & objectSid
 GetProp = "?"
 GetProp = CStr(strProp)
 End If
' End If
End Function

Function GetDomain()
 strDomain = WshNetwork.UserDomain
 If strDomain = "" Then
 strKey = "HKLMSystemCurrentControlSetServicesVxDVNETSUPWorkgroup"
 strDomain = WshShell.RegRead(strKey)
 End If
 GetDomain = strDomain
End Function

Additional Expert Help:
Be sure to check our Answer FAQ for more expert advice.
For faster answers, visit ITKnowledge Exchange.

This was last published in November 2004

Dig Deeper on Windows administration tools

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.