Question:
Hi I’m trying to get ONE LEVEL of the command Get-User –OrganizationalUnit.
1 2 |
Get-User –OrganizationalUnit "domain.local/ou/this-one" |
This returns the this-one ou and everything under it, I want a one level return, what paramteres am I missing?
Answer:
Create an array based on distinguished property :
1 2 3 4 |
$aduserinfo = get-aduser -Identity "Username here" $ou = $aduserinfo.distinguishedname.split(",")[2] $ou = $ou.substring(3) |
Play around With the index [2] and you will get the OU you search for.
Substring
removes the 3 first characters “ou=” in the index.