如何在不收到以下错误的情况下将证书复制到远程:
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
}
}