I have a list of Active Directory group name in the form
cn=GROUPA,ou=Dept1,ou=Departmental Groups,ou=GROUPS1,dc=test,dc=server,dc=com
and I was wondering if there was a way to use the -replace function to remove all of the "ou=" and "dc=" sections. I know I could just use
-replace "ou=Dept1",""
but I want to know if there is a way I could replace "ou=Dept1" without knowing the Dept1 part, since not all of the group names include Dept1, but instead use other names. I was thinking maybe some way of using select-string with a -notlike, but I have not found a way yet. Thank you.