Pages

3/26/2012

Powershell - List AD users and Home Directory

#LIST Home Directories
#AD List users & home dirs
$outfile = "c:\dev\home-list.csv"
$ou = "TestOU"
$ou = ""
$Search = New-Object DirectoryServices.DirectorySearcher([ADSI]"LDAP://OU=$ou,DC=USA,DC=DOMAIN,DC=COM")
$Search.filter = "(&(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" #users, not disabled
Foreach($result in $Search.Findall()){
 $user = $result.GetDirectoryEntry()
 $report = write-host "$($user.sAMAccountName),$($user.HomeDirectory)"
 $report
 $report | out-file -encoding ASCII $outfile -append
}

No comments: