Finding the users home drives

To display the home drive information for your users

"`nMicrosoft"            
Get-ADUser -LDAPFilter "(&(objectclass=user)(objectcategory=user)(homeDirectory=*))" -Properties *|            
Format-Table Name, DistinguishedName, HomeDirectory, HomeDrive -AutoSize            
            
"`nAD provider"            
Get-ChildItem -Filter "(&(objectclass=user)(objectcategory=user)(homeDirectory=*))" `
 -Path Ad:\"DC=Manticore,DC=org" -Recurse |             
foreach {             
 $user = [adsi]"LDAP://$($_.DistinguishedName)"            
 $user | select @{N="Name"; E={$_.name}},             
 @{N="DistinguishedName"; E={$_.distinguishedname}},            
 @{N="HomeDirectory"; E={$_.homeDirectory}},            
 @{N="HomeDrive"; E={$_.homeDrive}}             
} | Format-Table -AutoSize            
             
"`nQuest"            
Get-QADUser -LDAPFilter "(&(objectclass=user)(objectcategory=user)(homeDirectory=*))" -IncludeAllProperties |            
Format-Table Name, DN, HomeDirectory, HomeDrive -AutoSize            
            
"`nScript"            
$root = [ADSI]""            
$search = [adsisearcher]$root            
$search.Filter = "(&(objectclass=user)(objectcategory=user)(homeDirectory=*))"             
$search.SizeLimit = 3000            
$search.FindAll() | foreach {            
             
$user = $_.GetDirectoryEntry()            
$user | select @{N="Name"; E={$_.name}},             
 @{N="DistinguishedName"; E={$_.distinguishedname}},            
 @{N="HomeDirectory"; E={$_.homeDirectory}},            
 @{N="HomeDrive"; E={$_.homeDrive}}             
} | Format-Table -AutoSize

In all cases perform an LDAP search with the filter set for any occurrence of the the home directory being set.

The cmdlets can immediately display the required attributes but for the provider and script we have to get a directory entry so we can select the required attributes.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

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