Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File Powershell';被另一个进程使用';使用silentlyContinue显示时出错_File_Powershell - Fatal编程技术网

File Powershell';被另一个进程使用';使用silentlyContinue显示时出错

File Powershell';被另一个进程使用';使用silentlyContinue显示时出错,file,powershell,File,Powershell,我有一个脚本,它执行从一个Windows共享到另一个Windows共享的复制项目,偶尔会显示错误“无法访问该文件,因为它正被另一个进程使用”。执行此操作的代码如下所示,并且已包含-ErrorAction SilentlyContinue,但控制台上仍会显示错误: Get-ChildItem $sourceDir -Filter $itemNum*.* | ForEach { Copy-Item -LiteralPath $sourceDir\$_ -Destination $de

我有一个脚本,它执行从一个Windows共享到另一个Windows共享的复制项目,偶尔会显示错误“无法访问该文件,因为它正被另一个进程使用”。执行此操作的代码如下所示,并且已包含-ErrorAction SilentlyContinue,但控制台上仍会显示错误:

Get-ChildItem $sourceDir -Filter $itemNum*.* | ForEach {    
    Copy-Item -LiteralPath $sourceDir\$_ -Destination $destDir -ErrorAction SilentlyContinue
}
我有额外的代码来处理无法复制项目的情况,这非常有效,我只是不希望控制台上显示红色错误消息。由于“-errorAction SilentlyContinue”似乎不起作用,是否有其他方法

PS.总是导致问题的文件类型是.msg文件。有什么原因会有问题吗?我总是认为这是因为他们有嵌入的附件和文件等,并有可能被扫描的访问AV作为他们的GCI的结果


Powershell是在Windows Server 2008上运行的3.0版。

在相当多的命令中都会出现这种情况,这真的很烦人。要解决此问题,您可以尝试使用try/catch,如以下基本示例所示:

Get-ChildItem $sourceDir -Filter $itemNum*.* | ForEach {    
   try { 
        Copy-Item -LiteralPath $sourceDir\$_ -Destination $destDir -ErrorAction Stop
   } 
   catch {}
}

这在很多命令中都会发生,这真的很烦人。要解决此问题,您可以尝试使用try/catch,如以下基本示例所示:

Get-ChildItem $sourceDir -Filter $itemNum*.* | ForEach {    
   try { 
        Copy-Item -LiteralPath $sourceDir\$_ -Destination $destDir -ErrorAction Stop
   } 
   catch {}
}

您的
Get ChildItem
是否生成错误?或
复制项目
?如果没有错误消息详细信息,我们无法判断。
SilentlyContinue
隐藏非终止错误,而不是终止错误。(PowerShell中有两种错误。)要捕获终止错误,您需要
try
/
catch
。您的
Get ChildItem
是否生成错误?或
复制项目
?如果没有错误消息详细信息,我们无法判断。
SilentlyContinue
隐藏非终止错误,而不是终止错误。(PowerShell中有两种错误。)要捕获终止错误,您需要
try
/
catch
。请记住,这将捕获并忽略所有错误,而不仅仅是“正在使用”的错误。请记住,这将捕获并忽略所有错误,而不仅仅是“正在使用”的错误。