Hi Team.
I am trying to get the First Name and LastName from the accounts DN. I am close but i am not great at RegEx
When i output the code below its including the \, still in the last name section. How can i remove that as well?
First Name: Craig
Last Name: McFarlane\,
$dn = "CN=McFarlane\, Craig,OU=blah-blah" if ($dn -match "CN=([^ ]+) ([^,]+),") { $LastName = $matches[1] $FirstName = $matches[2] } # Output results Write-Output "First Name: $firstName" Write-Output "Last Name: $lastName"
Thanks in advance