如何将Cert复制到远程服务器

时间:2015-09-21 20:54:15

标签: powershell certificate

如何在不收到以下错误的情况下将证书复制到远程:

Copy-Item : Source and destination path did not resolve to the same provider.

这是我的代码:

$CertsCheck = Get-ChildItem -Path $origpath -D -recurse | Where-Object { $_.name -eq "Certs" } 

$PublicCert = "CERT:\LocalMachine\TrustedPeople"
$PrivateCert = "CERT:\LocalMachine\My"

if  (!$CertsCheck) { Write-Host "Certs directory doesn't exist in $origpath." }

else {
    $CertsDirectory = Get-ChildItem -Path $OctopusOriginalPackageDirectoryPath | foreach-object -process { $_.FullName } | Select-String -Pattern "Certs"
    $PublicCertExistTest = $PublicCert + "\$file"
    $PrivateCertExistTest = $PrivateCert + "\$file"

    foreach ( $file in Get-ChildItem -Path $CertsDirectory -Recurse )
    {
        $PrivateCertExistTest = $PrivateCert + "\$file"
        if (( $file -like "*.pfx") -and (-Not (Test-Path $PrivateCertExistTest )))  {
            Copy-Item $file.FullName $PrivateCert
            Write-Host "$file was copied" to $Privatecert

    }
        $PublicCertExistTest = $PublicCert + "\$file" 
        if (( $file -like "*.cer*" ) -and (-Not (Test-Path $PublicCertExistTest )))  {
            Copy-Item $file.FullName $PublicCert
            Write-Host "$file was copied" to $PublicCert
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用PowerShell的Import-Certificate cmdlet。