Active Directory Script Get User's Home folder and Terminal Services Profile

I am needing a script to gather all users in an OU and list their Home folder and their Terminal Services Profile in a text file.  With this information i need delete the home folder and Profile from the servers.  Also i need their email address so i can delete them for our external spam/Virus scanning provider.   All users in the OU will be deleted after this information is collected
pmcguireAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

binarykukiCommented:
Replace LDAP:// value and text file location. And you are done. All if you need more attribute check this site out http://www.winzero.ca/Active-Directory-users.htm
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", ForAppending, True)
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://dc=fabrikam,dc=com' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
	ObjTextFile.writeline  objRecordSet.Fields("SamAccountname").Value & "," & objRecordSet.Fields("homedirectory").Value & "," & objRecordSet.Fields("TerminalServicesProfilePath").Value
    objRecordSet.MoveNext
Loop
ObjTextFile.close

Open in new window

0
HaddionCommented:
You can use the csvde command line tool to do this.  Something like this should work.
CSVDE -d "OU=Users,DC=domain,dc=com" -r objectCategory=person -l "cn, profilePath, homeDirectory, mail"-f users.csv

Open in new window

0
pmcguireAuthor Commented:
Forgive me for being dumb.  Both of these sound like they will work but i don't know how to implement them.  The first on i copied to notepad and modified for my domain and saved it as a vbs file.  Ran it and i get nothing.  The second copied it to notepad and saved as a bat file.  Still nothing.  I am running from a workstation.  Should i be on a domain controller?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

HaddionCommented:
You need to adjust mine, so it has the correct OU information, then run it on the domain controller.
0
binarykukiCommented:
This definitely works
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=test,DC=my,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("ProfilePath").Value
    
    objRecordSet.MoveNext
Loop
Objtextfile.WriteBlankLines(2)
ObjTextfile.WriteLine("Total Records found:" & objRecordset.RecordCount)
Objtextfile.WriteBlankLines(2)
ObjTextFile.close

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
binarykukiCommented:
Has this solution worked for you?
0
pmcguireAuthor Commented:
The last bit of code read the ou i wanted but only wrote the summary to the text file.
02/05/2008
Total Records found:64

What needs to change to get it to list the info for each user in the OU?
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

Open in new window

0
pmcguireAuthor Commented:
I could not get the terminal services profile path to work.  everything else works when you take the terminal services profile out.  Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.