Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
当源是不存在的网络共享时,复制项PowerShell将以静默方式继续_Powershell_Copy Item - Fatal编程技术网

当源是不存在的网络共享时,复制项PowerShell将以静默方式继续

当源是不存在的网络共享时,复制项PowerShell将以静默方式继续,powershell,copy-item,Powershell,Copy Item,我在Copy Item cmdlet中看到一种奇怪的行为。如果源位置是不存在的本地位置,则cmdlet看起来会出错,但如果源位置是不存在的网络位置,则会完全忽略该错误 例如 Copy-Item \\server\share\thisdoesnotexist\* -Destination c:\temp -ErrorAction Stop 即使源共享无效,此命令也不会显示任何错误。但是, Copy-Item c:\thisdoesnotexist\* -Destination c:\temp -

我在Copy Item cmdlet中看到一种奇怪的行为。如果源位置是不存在的本地位置,则cmdlet看起来会出错,但如果源位置是不存在的网络位置,则会完全忽略该错误

例如

Copy-Item \\server\share\thisdoesnotexist\* -Destination c:\temp -ErrorAction Stop
即使源共享无效,此命令也不会显示任何错误。但是,

Copy-Item c:\thisdoesnotexist\* -Destination c:\temp -ErrorAction Stop
抛出一个错误,如下所示:

Copy-Item : Cannot find path 'C:\thisdoesnotexist' because it does not exist.
At line:1 char:1
+ Copy-Item c:\thisdoesnotexist\* -Destination c:\temp -ErrorAction Stop;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\thisdoesnotexist:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
这是怎么回事?我查过了,但没有看到任何关于这件事的信息。我的问题是:

这是预期的吗

当源网络共享也无效时,是否有方法使cmdlet失败


谢谢你的指点

我可以用PowerShell 3.0确认这些发现。可能是一个bug,但无论如何,在使用测试路径之前测试这些路径将是一个很好的措施。这可能是因为两个不同的提供程序都在使用文件系统提供程序,对吗?在Powershell 4.0上也会发生这种情况。当您删除星号时,它将给出正确的错误。在任何情况下,您都应该在执行复制项目之前测试路径。我将在复制之前使用测试路径,以确保它们存在。我也把这个贴在了。如果你们中有人可以投票,也许这会有助于吸引他们。