I'm trying to grab a value from a string within my PowerShell script.
The string can come like this:
$TargetOU = "OU=Company Users,OU=Company,OU=Organisation Users,DC=domain,DC=local"
or like this:
$TargetOU = "OU=Company,OU=Organisation Users,DC=domain,DC=local"
Using the following will return "Company" in the first example but "Company,OU" in the second. How Can I modify this to provide just "Company" in both instances?
$TargetOU.Split('= ')[1]