Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1237
  • Last Modified:

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.
0
2LL
Asked:
2LL
  • 2
  • 2
1 Solution
 
Shift-3Commented:
Try 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 AdsPath 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
    Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
    ObjTextfile.WriteLine objUser.CN & vbTab & objUser.homeDirectory & vbTab & objUser.TerminalServicesProfilePath
   
    objRecordSet.MoveNext
Loop
Objtextfile.WriteBlankLines(2)
ObjTextfile.WriteLine("Total Records found:" & objRecordset.RecordCount)
Objtextfile.WriteBlankLines(2)
ObjTextFile.close

Open in new window

0
 
2LLAuthor Commented:
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?
0
 
Shift-3Commented:
Ok, change objUser.TerminalServicesProfilePath to objUser.TerminalServicesHomeDirectory.
0
 
2LLAuthor Commented:
Thanks. It's worked.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now