Powershell e le OU (organizational units : unità organizzative) : come scoprire in quale OU risiede un utente di active directory con powershell?
Interesting question – how do you discover the OU in which an AD user is sitting? The Quest cmdlets were very helpful because they had a ParentContainer property. With the Microsoft cmdlets you have to do a bit of work
There are two places to look – the distinguished name and the canonical name
PS> $user = Get-ADUser -Identity Richard -Properties Canonicalname
PS> $user
Notice the different formats
The distinguished name is easiest
PS> ($user.DistinguishedName -split “,”, 2)[1]
CN=Users,DC=Manticore,DC=org
use split on the DistinguishedName. Note the format of the split command – – – “,”, 2
It means split on a comma and give me two elements – one containing the data before the first comma & the second containing all data after the first comma
The canonical name needs a bit more work
PS> $elements = $user.CanonicalName -split ‘/’
PS> $elements[0..($elements.Count – 2)] -join ‘/’
Manticore.org/Users
split the canonical…
View original post 12 altre parole
Discussione
Non c'è ancora nessun commento.