Q

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
 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

Dig deeper on Microsoft Active Directory Scripting

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close