i need your help. I would like to display a specific OU of an Object of our AD. The issue is that i want to display the OU only under "Country" (_Global, DE, IN)
For example (Get-ADUser):
Code: Select all
DistinguishedName : CN=Test\, User,OU=NewUsers,OU=_Global,OU=Country,DC=company,DC=com
DistinguishedName : CN=Test\, User2,OU=Users,OU=DE,OU=Country,DC=company,DC=com
DistinguishedName : CN=Test\, User3,OU=Users,OU=IT,OU=IN,OU=Country,DC=company,DC=com
For your information: The Path OU=Country,DC=company,DC=com is always the same
My approach:
Code: Select all
$user= get-aduser user
$path= $user.DistinguishedName
$path-split "," | where {$_ -like "OU=*"}
Result:
OU=NewUsers
OU=_Global
OU=Country
Best regards