I have certificate information from websites in powershell, they usually look like this
CN=Google Internet Authority G3, O=Google Trust Services, C=US
I need help getting the right regex to only take the information after CN= up to the comma
Second issue is some of the certificates I am getting only have a CN= and therefore there is no comma at the end so it would look like
CN=Google Internet Authority G3
How can I use regex to catch either case?
Here is what I thought would worked and tried :
$cert.Issuer -match "CN=(?<issuer>.*(?=,))"
Write-Host $Matches['issuer']
>> Google Internet Authority G3, O=Google Trust Services
$cert.Issuer -match "CN=(?<issuer>.*)?,?\s"
Write-Host $Matches['issuer']
>> Google Internet Authority G3, O=Google Trust Services,
$cert.Issuer -match "CN=(?<issuer>.*),|\s"
Write-Host $Matches['issuer']
>> Google Internet Authority G3, O=Google Trust Services
So I want to just get
Google Internet Authority G3
whether it has a comma and then more information or does not have a comma and is the end of the string
Thanks!