Powershell to Get HomeDirectory details for the given list of users

 

Below code helps to get the list of HomeDirectory Path for the given list of users in the text file as input

$UserList = Get-Content “c:\users.txt”
$domain = [ADSI]””
foreach($UserName in $UserList)
{ $searcher = new-object DirectoryServices.DirectorySearcher($domain)
$searcher.filter = “(&(objectClass=user)(sAMAccountName= $UserName))”
$SearchResult = $searcher.findall() | select Properties
$Homepath = $username + ” –  ” + $SearchResult.properties.homedirectory
$Homepath
}

Leave a comment