PowerShell: Get-User -OrganizationalUnit One Level?

Hi, I'm trying to get the ONE LEVEL of the Get-User -OrganizationalUnit command.

Get-User –OrganizationalUnit "domain.local/ou/this-one"

This returns this one and everything below it, I want to return one level, what parameters are missing for me?

+5
source share
3 answers

Create an array based on the selected property:

$aduserinfo = get-aduser -Identity "Username here"
$ou = $aduserinfo.distinguishedname.split(",")[2]
$ou = $ou.substring(3)

Play with the index [2] and you will get the OU that you are looking for. Substringremoves the first 3 characters of "ou =" in the index.

+2
source

There is no specific parameter for this, how about using a filter?

Like this:

Get-User -Filter "distinguishedName -like 'CN=*,OU=This-one,OU=OU,DC=domain,DC=local'"

Otherwise, get-aduser cmd-let allows you to specify the search scope as follows:

get-aduser -searchbase "OU=This-one,OU=OU,DC=domain,DC=local" -searchscope 1

Link: http://technet.microsoft.com/en-us/library/ee617241.aspx

Arcass

+1

, , , , :

Get-ADOrganizationalUnit -Searchbase "OU=OUYouareSearching,DC=domain,DC=net" -SearchScope OneLevel -Filter *

-SearchScope OneLevel - .

0

All Articles