2016-07-15 52 views
0

我試圖在使用Test-Path複製它之前檢查位置是否存在。據我瞭解,這應該返回true或false,取決於位置是否存在。當測試位置是否存在時,Test-Path返回異常

我的代碼

if (Test-Path $updatedsource) { 
    Copy-Item $updatedsource $record.Target -Recurse -Container -Force 
} 

而不是真或假,這條線拋出異常

Test-Path : An object at the specified path 
\\wnasdce03\SECENV_PROD-01\Users\Results\thorn-01.00rc3\ICEVol_BC_20160715 
does not exist 
At \\VFIPPFIL005\EMT_Projects\Vimmi\SE\CoypHistoryData.ps1:31 char 22 
+ if (Test-Path <<<< $updatedsource) { 
    + CategoryInfo: ObjectNotFound: (\\wnasdce03\SEC...tC_20160716:String) [Test-Path1. IOException 
    + FullyQualifiedErrorId : ItemDoesNotExist.Microsoft.Powershell.Commands.TestPathCommand

爲什麼我會得到一個例外,該位置不存在?當然這應該只是返回false?

+1

基於輸出看起來像\ wnasdce03 \ SECENV_PROD-01 \用戶\結果\刺01.00rc3 \ ICEVol_BC_20160715 wnasdce03是computername它應該去\\ wnasdce03 – DisplayName

+0

請不要破壞PowerShell錯誤。張貼他們*完全*因爲他們是。至於你的問題,在肢體上出去,我懷疑在手術過程中,子文件夾被刪除了。 –

回答

0

你想改變你的erroraction詳情如下命令:

if (Test-Path $updatedsource -ErrorAction SilentlyContinue) 
{ 
    Copy-Item $updatedsource $record.Target -Recurse -Container -Force 
}