List Linux Users in Active Directory using PowerShell

A PowerShell script to list Linux users in Active Directory:  This script will search for users in your Active Directory that have the unix attributes set. The unix attributes that are most often used are uidNumber, gidNumber, unixHomeDirectory, and loginShell. The script does a search for users whose uidNumber = * meaning that it is set to something other than blank, returns the results, and displays the attributes. This is very handy since Microsoft does not display these attributes in the GUI.  For more information on how to setup Active Directory users to logon to Linux, please see our index of articles related to Active Directory Authentication for Linux

$domain = New-Object System.DirectoryServices.DirectoryEntry
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $domain
$searcher.PageSize = 1000
$searcher.Filter = "(&(objectCategory=User)(uidNumber=*))"
$proplist = ("cn","displayName","uidNumber","gidNumber","unixHomeDirectory","loginShell")
foreach ($i in $propList){$prop=$searcher.PropertiesToLoad.Add($i)}
$results = $searcher.FindAll()
$results ¦ %{ $_.properties; "" }

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...