Con Windows 2012 R2 (Win 8.1) y por exceso, también tienen la "oficial" Import-PfxCertificate cmdlet
Aquí están algunas partes esenciales del código (un ejemplo adaptables):
Invoke-Command -ComputerName $Computer -ScriptBlock {
param(
[string] $CertFileName,
[string] $CertRootStore,
[string] $CertStore,
[string] $X509Flags,
$PfxPass)
$CertPath = "$Env:SystemRoot\$CertFileName"
$Pfx = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
# Flags to send in are documented here: https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509keystorageflags%28v=vs.110%29.aspx
$Pfx.Import($CertPath, $PfxPass, $X509Flags) #"Exportable,PersistKeySet")
$Store = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $CertStore, $CertRootStore
$Store.Open("MaxAllowed")
$Store.Add($Pfx)
if ($?)
{
"${Env:ComputerName}: Successfully added certificate."
}
else
{
"${Env:ComputerName}: Failed to add certificate! $($Error[0].ToString() -replace '[\r\n]+', ' ')"
}
$Store.Close()
Remove-Item -LiteralPath $CertPath
} -ArgumentList $TempCertFileName, $CertRootStore, $CertStore, $X509Flags, $Password
basado en el código de mao47 y algunas investigaciones, redactó un litt le artículo y un cmdlet simple para importar/enviar certificados PFX a computadoras remotas.
Here's mi artículo con más detalles y un código completo que también funciona con PSv2 (predeterminado en Server 2008 R2/Windows 7), siempre que tenga habilitado SMB y acceso compartido de administración.
Es frustrante que CertUtil no puede importar un PFX a TRUSTEDPEOPLE. CertUtil funciona bien con un PSSession remoto (PowerShell), pero importpfx no (FYI, fuente de importpfx es http://home.fnal.gov/~jklemenc/src/importpfx.cpp). No estoy seguro de qué es lo que CERTUTIL está haciendo de manera diferente, pero * does * funciona con sesiones de PS remotas, pero no puedo ubicar el certificado en Trusted People. Suspiro. Un par de días muy frustrante. –
Terminamos escribiendo un conjunto de funciones de powershell para hacer el trabajo duro. Mire CiPsLib.Certificates.psm1 -> Import-Certificate https://github.com/rasmus/CiPsLib/tree/master/tools – jaspernygaard
¿Cómo puedo importar sin usar una contraseña? ¿Es posible? – drgmak