$tempPath = "c:\work" $password = "P@ssword" if (Test-Path ($tempPath)) { $certs = Get-Item (Join-Path $tempPath "*.pfx") if ($certs.Count -gt 0) { If (!(test-path "cert:\localmachine\Shielded VM Local Certificates")){ New-Item -Path "cert:\localmachine" -Name "Shielded VM Local Certificates" } ForEach ($cert in $certs) { $filename = Join-Path $tempPath $cert.Name Import-PfxCertificate -FilePath $filename -CertStoreLocation "Cert:\LocalMachine\Shielded VM Local Certificates" -Password (ConvertTo-SecureString -String $password -Force -AsPlainText) } } else { Write-Host "PFX file does not exist in $($tempPath) ." } } else { Write-Host "$($tempPath) does not exist." }