Link to home
Start Free TrialLog in
Avatar of 2LL
2LL

asked on

Script Get User's Home folder and Terminal Services Profile

I am looking for the script that list users home folder and terminal service home directory within OU. I found the following script on this forum, but everytime I ran it, it does not show any record at all eventhougt it does not have any error. Someone please help me out with this.

On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\OUUserlist.txt", 8, True)
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
objCommand.CommandText = _
    "SELECT Name,homedirectory,ProfilePath FROM 'LDAP://OU=PENDING DELETION,DC=ftsad,DC=com' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
ObjTextfile.WriteLine(Date)
Objtextfile.WriteBlankLines(2)
Do Until objRecordSet.EOF
      ObjTextFile.writeline  objRecordSet.Fields("Name").Value & vbTab & objRecordSet.Fields("homedirectory").Value & vbTab & objRecordSet.Fields("TerminalServicesProfilePath").Value
   
    objRecordSet.MoveNext
Loop
Objtextfile.WriteBlankLines(2)
ObjTextfile.WriteLine("Total Records found:" & objRecordset.RecordCount)
Objtextfile.WriteBlankLines(2)
ObjTextFile.close


Thank you in advance.
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 2LL
2LL

ASKER

Hello Shift-3, thank you for for correction. However, it show up like the user home directory only, as soon as I remove the line "& objUser.homeDirectory & vbTab" It show some (only 2) users Terminal Service Home Directory, the true is most all them (267 users) should have Terminal Service Home Directory. Is there any script I can get Terminal Service Home Directory?
Ok, change objUser.TerminalServicesProfilePath to objUser.TerminalServicesHomeDirectory.
Avatar of 2LL

ASKER

Thanks. It's worked.