I need the marked part bellow of the distinguished name of an computer:
CN=X, OU=EXAMPLEOU, OU=D, DC=A, DC=B, DC=C
I just need OU=EXAMPLEOU
.
How I get this part of the distinguished name:
$OU = Get-ADComputer -Identity $env:computername -Properties * | select @{N="OU";E={$_.DistinguishedName.Split(',')[-5].split('=')[1]}}
The output is:
OU
___
EXAMPLEOU
BUT I want the endresult to be a string that just returns EXAMPLEOU
.
How can I do that? THANK YOU!