2014-01-22 4 views
4

makecert.exe로 만든 인증서 (X.509)를 원격 서버에 설치하려고합니다. psexec 같은 것을 사용할 수 없지만 PowerShell을 사용해야합니다.원격 서버에 PowerShell로 인증서 설치

  • 서버 운영 체제 : Windows Server 2008 R2의
  • PowerShell을 버전 : 4

질문 : 원격 서버에 PowerShell을 가진 인증서를 설치하는 방법.

+0

원격 서버의 OS 및 PSH 버전은 무엇입니까? – Richard

+0

원래 질문에 정보를 추가했습니다. –

+0

두 시스템 모두에서 PowerShell 원격 활성화가 가능하며 두 시스템이 서로 신뢰됩니다. " –

답변

1

예를

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

를 들어, Import-PfxCertificate을 사용할 수있는 PFX 파일을 가져 오려면 원격 컴퓨터에서이 작업을 수행하려면 Invoke-Command -ComputerName을 사용할 수 있습니다 (UNC 경로를 사용하여 PFX 파일).

2

시나리오 :

$afMachineName = "SomeMachineNameOrIp" 
$certSaveLocation = "c:\temp\Cert.CER" 
  • 는 두 시스템에 대한 신뢰 (ServerA가 & 수 있도록 : ServerA가에서 SSL 인증서를 가지고, 서버 B에서 SSL 인증서가

    1. 이 두 변수 (서버 B 만)를 정의 수입 싶습니다 서버 B) :

      Function enableRemotePS() { 
          Enable-PSRemoting -Force 
          Set-Item wsman:\localhost\client\trustedhosts $afMachineName -Force 
          Restart-Service WinRM 
      } 
      
    2. 는 C를 저장 ertificate (서버 B 만) :

      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 
      } 
      
    3. 가져 오기 인증서 (전용 서버 B)

      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() 
      }