enter code here
Возникла проблема при репликации файлов на удаленный сервер, сбой пути каким-либо образом. Ниже приведен код:
Invoke-Command -ComputerName $RemoteServer -ScriptBlock {param($DestinationDir,$LocalCertResultObj,$RemoteCertResultObj,$SourceDir) Compare-Object $LocalCertResultObj $RemoteCertResultObj -Property Name, Length, FullName | Where-Object {$_.SideIndicator -eq "<="} | ForEach-Object {
{$DestinationDir = Join-Path $DestinationDir $_.FullName.Substring($SourceDir.length)}
Write-Output $DestinationDir
Write-Output $SourceDir
Copy-Item -Path "$SourceDir\$($_.name)" -Destination "$DestinationDir" -Recurse -Force
} } -ArgumentList $DestinationDir,$LocalCertResultObj,$RemoteCertResultObj,$SourceDir -Credential $RemoteMachine_cred
Получение ошибки, как показано ниже:
$DestinationDir = Join-Path $DestinationDir $_.FullName.Substring($SourceDir.length)
C:\TestFolderR
C:\TestFolder
Cannot find path 'C:\TestFolder\file1.txt' because it does not exist.
+ CategoryInfo : ObjectNotFound: (C:\TestFolder\file1.txt:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand