Powershell同步脚本试图覆盖源文件而不是复制到目标

时间:2019-02-27 07:36:53

标签: linuxmint powershell-core

此脚本试图覆盖源文件,而不是复制到目标位置,我不确定为什么。在将Powershell Core更新到6.1之前,它已按预期运行。该脚本旨在在不包含文件夹的情况下同步音乐目录。

if (Test-Path /fileserver/MP3playerMusic)
{
    $sourcefiles = Get-ChildItem /fileserver/MP3PlayerMusic -Recurse | where {$_.PSIsContainer -eq $false -and $_.Extension -ne ".dat"} 
    $destinationfiles = Get-ChildItem /home/username/Music -Recurse | where {$_.PSIsContainer -eq $false -and $_.Extension -ne ".dat" } 
    $destinationdirectories = "/home/username/Music"
    $filedifferenceobject = Compare-Object -ReferenceObject $sourcefiles -DifferenceObject $destinationfiles
    $filedifferenceobject | foreach { $copyparams = @{'path' = $_.inputobject.fullname} 
    if ( $filedifferenceobject.sideindicator -eq '<=' )
                { "files are not synced"
              "Syncing files"
              $copyparams.Destination = $destinationdirectories
              Copy-Item @copyparams -Verbose
             }
        else
        { "files are synced" }
    }
}

0 个答案:

没有答案