What's the easiest way to get the OU containing an LDAP object in PowerShell?
I'm working on a script to manage some groups that I've made "dynamic" with a script, and I can get the full distinguished name with the below:
$PseudoDynamicGroupDN = (Get-ADGroup -Filter {Name -like $PseudoDynamicGroup}).DistinguishedName
It returns something like:
CN=MyPseudoDynamicGroup,OU=Users,OU=BusinessUnit,OU=Site,OU=Company,DC=domain,DC=forest,DC=tld
And I'm looking to discard the CN=MyPseudoDynamicGroup,
bit so I end up with:
OU=Users,OU=BusinessUnit,OU=Site,OU=Company,DC=domain,DC=forest,DC=tld
How do I do this as easily as possible? I tried using the Split operator, but this returns an array, and strips out the commas, forcing me to add them back in. I suspect there's a better way.