Tip: You can extract the CN (Common Name) from DN (Distinguished Name) in Active Directory.
For example, someone sent you one report with DN only and you need to extract the CN.
1 2 3 4 5 6 7 |
$distinguishedName = 'CN=SMITH John,OU=Managers,OU=EMEA,DC=contoso,DC=com' # Solution 1 $distinguishedName -replace "(CN=)(.*?),.*",'$2' # Solution 2 ($distinguishedName -split ',*..=')[1] |