Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: Get-User –OrganizationalUnit One Level?

Tags:

powershell

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?

like image 340
basickarl Avatar asked Oct 24 '22 01:10

basickarl


2 Answers

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.

like image 117
Tommy Avatar answered Nov 03 '22 05:11

Tommy


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

like image 25
Arcass Avatar answered Nov 03 '22 04:11

Arcass