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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s