无法将参数“ Path”绑定到参数,因为它为NULL

时间:2018-12-20 18:49:17

标签: powershell

我一直在尝试编写用于同步文件夹的PowerShell脚本,并使用了指南"How to Sync Folders With PowerShell"。不幸的是我遇到一个错误。指南可能会被弃用吗?

$Folder1Path = 'C:\Users\Name\OneDrive'
$Folder2Path = 'C:\Users\Name\Documents\Folder'

$Folder1Files = Get-ChildItem -Path $Folder1Path
$Folder2Files = Get-ChildItem -Path $Folder2Path

$FileDiffs = Compare-Object -ReferenceObject $Folder1Files -DifferenceObject $Folder2Files

$FilesDiffs | foreach {
    $copyParams = @{
        'Path' = $_.InputObject.FullName
    }

    if ($_.SideIndicator -eq '<=') {
        $copyParams.Destination = $Folder2Path
    } else {
        $copyParams.Destination = $Folder1Path
    }
    Copy-Item @copyParams
}

错误消息:

Copy-Item: Cannot bind the parameter "Path" to the argument, since it is NULL.
In C:\Users\Name\Documents\PowerShell Scripts\Script.ps1:21 symbol:12
+     Copy-Item @copyParams
+               ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand

0 个答案:

没有答案