Hi I'm trying to get ONE LEVEL of the command Get-User –OrganizationalUnit.
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?
Create an array based on distinguished property :
$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.
There isn't a specific parameter for doing this, how about using a filter?
Like this:
Get-User -Filter "distinguishedName -like 'CN=*,OU=This-one,OU=OU,DC=domain,DC=local'"
Failing that the get-aduser cmd-let allows you to set the scope of the search like this:
get-aduser -searchbase "OU=This-one,OU=OU,DC=domain,DC=local" -searchscope 1
Reference: http://technet.microsoft.com/en-us/library/ee617241.aspx
regards Arcass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With