Location: Articles

Articles

Articles

VBScript to dump Terminal Services profile paths to CSV file

By on Sunday, November 25, 2007 9:19 PM

A short VBScript that queries Active Directory and writes profile-related user information to CSV file.

I normally use CSVDE or ADFIND to dump user attributes to a CSV file, but because they both use LDAP queries neither of them is able to retrieve the value of the Terminal Services path.  The reason for this is that the Terminal Services profile settings (see screenshot below) are stored as an unreadable binary value in the userParameters attribute.

The script finds all user objects below a given DN (as specified by the value of strBase in red below). For every object that it finds it will write out the various values in comma separated format. The output values are shown in the table below:

 

Active Directory Users and Computers
LDAP Display Name
Name of object
cn
User logon name (pre-Windows 2000)
sAMAccountName
Terminal Services profile path
userParameters
Profile path
profilePath
Home folder
homeDirectory
Logon script
scriptPath

Option Explicit
Dim objCommand, objConnection, strBase, strFilter, strAttributes, objUser
Dim strQuery, objRecordset, strdistinguishedName, strTSPath, strCN
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
'...set the base DN
strBase = "<LDAP://DC=MYCO,DC=COM>"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "sAMAccountName,cn,distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
 
Do Until objRecordSet.EOF
  strdistinguishedName = objRecordSet.Fields("distinguishedName").Value
  Set objUser = GetObject("LDAP://" & strdistinguishedName)
  On error resume next
  Wscript.Echo objUser.cn & "," & objUser.sAMAccountName _
  & "," & objUser.TerminalServicesProfilePath & "," & objUser.profilePath _
  & "," & objUser.homeDirectory & "," &objUser.ScriptPath
  objRecordSet.MoveNext
Loop


objConnection.Close

To use the script to write out to a CSV file, simply use the following command line (assumes you have saved the script as profiledump.csv):

cscript profiledump.vbs > profiledump.csv
 
Alexei

24/03/2007


Rating
Comments
Currently, there are no comments. Be the first to post one!
Click here to post a comment
Friends

Friends

Namescape

Ads

Your Home Page ..

Site Articles:

Add to Google

Add to My Yahoo!

Mail List Posts:

Add to Google

Add to My Yahoo!

Friends

Friends

ScriptLogic
AdventNet Banner
Copyright 2008 ActiveDir.org
Terms Of Use