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

By Rutgers @ Wednesday, July 09, 2008 4:27 PM

I was unable to get this script to run successfully. I get the following error:

Provider: Table does not exist


By Luuk @ Wednesday, February 18, 2009 6:27 AM

Works fine ! I already found this information is in the userParameters attribute but did not have a way to extract it.


By Gavin Brown @ Friday, June 05, 2009 4:25 PM

Hi

I am looking at extracting the Terminal Service Profile path of all users from our active directory. I have constructed the script and it works fine if I do not want to show the profile path but once I add the code to do this the script falls over itself and fails to find any records where it previously found all. Any ideas why this would happen.


By vrk it @ Saturday, July 18, 2009 6:28 PM

Hi Gavin,

Iam also looking at extracting the Terminal Service Profile path and home directory of all users from our active directory.Could you please mail me the working copy of the script asap to vrkit@yahoo.com

Thanks in advance.

vrk


By Twila @ Wednesday, September 02, 2009 3:51 PM

Table does not exist error appears if you attempt to use OU= as well as DC=. Only the DC= context should be used


Click here to post a comment
Copyright 2009 ActiveDir.org
Terms Of Use