Ask the Expert

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? Contrarily, can I list users not configured as Roaming User Profiles?

    Requires Free Membership to View

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
 WScript.Quit
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 
&"_Users.CSV"
set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FileExists (fname) THEN
 set objFile = fso.GetFile (fname)
 objFile.Delete
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)
objUser.GetInfo
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)
aProps(0)="LastLogin"
aProps(1)="HomeDirectory"
aProps(2)="Profile"
objFile.WriteLine s


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

objFile.Close
Wscript.Echo "File Created: " & fname
Wscript.Quit



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 = "?"
 Else
 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 first published in November 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: