# Create searcher object
$Domain = "sub.domain.com"
$ADsPath = [ADSI]"LDAP://$Domain"
$searcher = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
$searcher.SearchScope = "Subtree"
$searcher.PageSize = 1000
# Restrict properties to load
# $searcher.PropertiesToLoad.Add("name")
# $searcher.PropertiesToLoad.Add("sAMAccountName")
# $searcher.PropertiesToLoad.Add("employeeID")
# $searcher.PropertiesToLoad.Add("mail")
# $searcher.PropertiesToLoad.Add("userPrincipalName")
$searcher.PropertiesToLoad.Add("memberOf")
$searcher.Filter = "(&(objectClass=User)(samAccountName=username))"
$colResults = $searcher.FindOne()
$objItem = $colResults.Properties
$objItem.Item("memberOf") | foreach-object {
write-host $_
}
Wednesday, January 3, 2018
Powershell code (local) to list user AD memberships
Powershell code snippet which you could run using PowerShell ISE window. Do not need to install additional modules, unlike Get-ADUser
Labels:
powershell
Subscribe to:
Post Comments (Atom)
2 comments:
Very informative post for mulesoft developers.You can also visit goformule.com for mulesoft stuff.
Very nice article,Thank you.
Keep updating...
ServiceNow Developer Training
Post a Comment