Retrieve Issuer thumbprint from a certificate using "System.Security.Cryptography.X509Certificates"

StackOverflow https://stackoverflow.com/questions/23431484

  •  14-07-2023
  •  | 
  •  

Pergunta

Is it possible to retrieve a issuer thumbprint from a certificate in a powershell script if I am using "System.Security.Cryptography.X509Certificates" ?

I have this powershell script that get all certs in "my" store on a remote server and than output it to a Format-Table. I would like to be able to know what is the issuer thumbprint withing the same script.

Param(

    [parameter(
    Mandatory=$true)]
    [String]$CSVFile
)

Set-ExecutionPolicy RemoteSigned

$Serveurs = import-csv $CSVFile
$Nom = $Serveurs.Nom

Foreach ($Serveur in $Serveurs){
        $x509store = new-object System.Security.Cryptography.X509Certificates.X509Store("\\$($Serveur.Nom)\My","LocalMachine")
        $x509store.Open('ReadOnly')
        $x509store.Certificates | Format-Table -Property FriendlyName,NotAfter,Thumbprint,Issuer,Subject
}

Thanks !

Foi útil?

Solução

I would recommend using what powershell has provided their is a psdrive to your certificate store.

Get-ChildItem -Path Cert:\LocalMachine\My | 
Format-Table -Property FriendlyName,NotAfter,Thumbprint,Issuer,Subject

Update:

I didn't notice that this was for a remote machine. You could rap that cmd inside of an Invoke-Command.

Invoke-Command -ComputerName "Computer1","Computer2",... -ScriptBlock {Get-ChildItem -Path Cert:\LocalMachine\My}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top