2014-01-22 3 views
4

Я хочу установить сертификат (X.509), созданный с помощью makecert.exe на удаленном сервере. Я не могу использовать psexec или что-то в этом роде, но должен использовать PowerShell.Установить сертификат с PowerShell на удаленном сервере

  • операционной системы сервера: Windows Server 2008 R2 версия
  • PowerShell: 4

Вопрос: Как установить сертификат с помощью PowerShell на сервере удаленного.

+0

Какая версия ОС и PSH на удаленном сервере? – Richard

+0

Я добавил информацию к исходному вопросу. –

+0

У вас есть возможность удаленного доступа PowerShell на обеих машинах, и обе машины доверяются друг другу »? –

ответ

1

Чтобы импортировать файл PFX, вы можете использовать Import-PfxCertificate, например

Import-PfxCertificate -FilePath YOUR_PFX_FILE.pfx -Password (ConvertTo-SecureString -String "THE_PFX_PASSWORD" -AsPlainText -Force) 

Чтобы сделать это на удаленном компьютере, вы можете использовать Invoke-Command -ComputerName (и использовать UNC-путь для PFX-файл).

2

Сценарий: ServerA имеет SSL сертификат, ServerB хотел бы, SSL сертификат импортирован

  1. определяют две переменные (ServerB только):

    $afMachineName = "SomeMachineNameOrIp" 
    $certSaveLocation = "c:\temp\Cert.CER" 
    
  2. позволяют доверие на обеих машинах (ServerA & ServerB):

    Function enableRemotePS() { 
        Enable-PSRemoting -Force 
        Set-Item wsman:\localhost\client\trustedhosts $afMachineName -Force 
        Restart-Service WinRM 
    } 
    
  3. Сохранить c ertificate (ServerB только):

    Function saveCert([string]$machineName,[string]$certSaveLocation) { 
        Invoke-Command -ComputerName $machineName -ArgumentList $certSaveLocation -ScriptBlock { 
         param($certSaveLocation) 
         $cert = dir Cert:\LocalMachine\Root | where {$_.Subject -eq "CN=YOURCERTNAME" }; 
         $certBytes = $cert.Export("cert"); 
         [system.IO.file]::WriteAllBytes($certSaveLocation, $certBytes); 
        } 
    
        Copy-Item -Path \\$machineName\c$\temp\CertAF.CER -Destination $certSaveLocation 
    } 
    
  4. Импорт сертификата (ServerB только)

    Function importCert([string]$certSaveLocation) { 
        $CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certSaveLocation 
    
        $CertStoreScope = "LocalMachine" 
        $CertStoreName = "Root" 
        $CertStore = New-Object System.Security.Cryptography.X509Certificates.X509Store $CertStoreName, $CertStoreScope 
    
        # Import The Targeted Certificate Into The Specified Cert Store Name Of The Specified Cert Store Scope 
        $CertStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 
        $CertStore.Add($CertToImport) 
        $CertStore.Close() 
    } 
    
Смежные вопросы