移动书签时Powershell复制项目错误

时间:2018-07-26 13:06:54

标签: windows powershell

我的脚本之一是将Google Chrome书签从网络上的一台计算机移动到另一台计算机。当我运行脚本时,它似乎正在运行,然后引发一个Copy-Item错误。可以肯定的是我的文件路径有问题,但是我不知道它是什么。

首先输入代码,然后出现错误:

     [CmdletBinding()]
param(
    [String]$SourceComputerName,
    [String]$DestinationComputerName,
    [String]$UserName
)
BEGIN {
    $ErrorActionPreference = 'Continue'
     $CMDOUT=@{ #This is used so that the function accepts -Verbose / -Debug parameters
        Verbose=If ($PSBoundParameters.Verbose -eq $true) { $true } else { $false };
        Debug=If ($PSBoundParameters.Debug -eq $true) { $true } else { $false }
    }

    $SourcePath = '\\' + $SourceComputerName + '\C$\users\' + $UserName + '\AppData\Local\Google\Chrome\User Data\Default' #Transfer Bookmarks from here
    $DestinationPath = '\\' + $DestinationComputerName + '\C$\users\' + $UserName + '\AppData\Local\Google\Chrome\User Data\Default' #Transfer Bookmarks to here
}

PROCESS{
    #Create copy of destination backup file, make sure not to overwrite other backup files that might exsist
    If(Test-Path ($DestinationPath + '\Bookmarks')){
        $i = 1
        do{
            $BackupPath = ($DestinationPath + '\Bookmarks') + '_' + $i.ToString('000') + '.old'
            $i++
        }
        while(Test-Path $BackupPath)
        Copy-Item -Path ($SourcePath + '\Bookmarks') -Destination $BackupPath @CMDOUT
    }

    #Copy Bookmarks to DestinationComputer
    Copy-Item -Path ($SourcePath + '\Bookmarks') -Destination ($DestinationPath + '\Bookmarks') -Force @CMDOUT
    #Replace the Chrome create Bookmark backup (.bak) file
    Copy-Item -Path ($SourcePath + '\Bookmarks') -Destination ($DestinationPath + '\Bookmarks.bak') -Force @CMDOUT

    #Copy Favicons (for bookmarks)
    If(Test-Path ($DestinationPath + '\Favicons')){
        Copy-Item -Path ($SourcePath + '\Favicons') -Destination ($DestinationPath + '\Favicons') -Force @CMDOUT
    }
}
END{
}

}

    Copy-Item : The network path was not found
  At C:\Users\Shane.goldsberry\PowerShellScripts\PS1\MigrateChromeBookmarks.ps1:61 char:9  
    Copy-Item -Path ($SourcePath + '\Bookmarks') -Destination ($D ...
+ CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand



    Copy-Item : The network path was not found At C:\Users\Shane.goldsberry\PowerShellScripts\PS1\MigrateChromeBookmarks.ps1:63 char:9  Copy-Item -Path ($SourcePath + '\Bookmarks') -Destination ($D ...  
+ CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

0 个答案:

没有答案