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] |
Pingback: Powershell Tip #122: Get the start time and end time of the current day | Powershell Guru
Pingback: Powershell Tip #124: Extract the OU (Organizational Unit) from DN (Distinguished Name) in Active Directory | Powershell Guru
+1, thanks, i like solution #2 for its logic