$tempPath = "c:\work" $password = "P@ssword" if (Test-Path ($tempPath)) { $certs = Get-Item "cert:\localmachine\Shielded VM Local Certificates\*" ForEach ($cert in $certs) { if (($cert.Subject).contains($env:COMPUTERNAME)) { $filename = ($cert.Subject -replace "CN=","") -replace " ", "_" $filename = $filename + ".pfx" $filename = Join-Path $tempPath $filename certutil -exportPFX -p $password "Shielded VM Local Certificates" $cert.Thumbprint $filename } } } else { Write-Host "$($tempPath) does not exist." }