如果我使用ls
命令在PowerShell中对磁盘进行完全递归搜索,并将ErrorAction
设置为SilentlyContinue
,当它遇到无法访问的文件夹时仍会发生炸弹。< / p>
我可以将呼叫包裹在try catch
中,但这不会阻止搜索终止,它只会吞下错误。
示例:
ls -Include msdeploy.exe -Recurse -ErrorAction SilentlyContinue;
结果:
PS C:\> ls msdeploy.exe -Recurse -ErrorAction SilentlyContinue
Directory: C:\Program Files\IIS\Microsoft Web Deploy V2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 4/1/2011 8:17 PM 165704 msdeploy.exe
Directory: C:\Program Files\IIS\Microsoft Web Deploy V3
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 7/12/2012 9:13 AM 197504 msdeploy.exe
Directory: C:\Program Files (x86)\IIS\Microsoft Web Deploy V2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 4/1/2011 8:17 PM 169800 msdeploy.exe
Directory: C:\Program Files (x86)\IIS\Microsoft Web Deploy V3
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 7/12/2012 9:13 AM 201600 msdeploy.exe
ls : Access is denied
At line:1 char:1
+ ls msdeploy.exe -Recurse -ErrorAction SilentlyContinue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand
我会尝试全局变量,我认为还有另一种方式。
答案 0 :(得分:2)
尝试设置$ErrorActionPreference = "silentlycontinue"
而不是使用参数-ErrorAction SilentlyContinue
。很久以前有人提到-EA
有时可能会起作用。
答案 1 :(得分:0)
所以Ansgar能够使错误无声,但在脚本中错误有效地默默地停止了执行。
我无处可去,心情不好。
我今天早上回到RDP到Windows Server 2008 R2虚拟机并且看不到它已经从Windows Update运行重新启动了。更令人惊奇的是,这个问题神秘地消失了!
时机令人难以置信。这些是更新:
Product
-------
Security Update for Microsoft .NET Framework 4.5 on Windows 7, Vista, Windows Server 2008, Windows Server 2008 R2 for x64 (KB2840642)
Windows Malicious Software Removal Tool x64 - July 2013 (KB890830)
Security Update for Windows Server 2008 R2 x64 Edition (KB2835361)
Security Update for Microsoft .NET Framework 3.5.1 on Windows 7 and Windows Server 2008 R2 SP1 for x64-based Systems (KB2840631)
Security Update for Windows Server 2008 R2 x64 Edition (KB2834886)
Security Update for Windows Server 2008 R2 x64 Edition (KB2850851)
Security Update for Microsoft .NET Framework 3.5.1 on Windows 7 and Windows Server 2008 R2 SP1 for x64-based Systems (KB2833946)
Cumulative Security Update for Internet Explorer 10 for Windows Server 2008 R2 Service Pack 1 for x64-based Systems (KB2846071)
Security Update for Microsoft .NET Framework 3.5.1 on Windows 7 and Windows Server 2008 R2 SP1 for x64-based Systems (KB2844286)
Security Update for Microsoft .NET Framework 3.5.1 on Windows 7 and Windows Server 2008 R2 for x64-based Systems (KB2832414)
但是,应该注意的是,它可能是重新启动的行为(这是一个服务器),它可能已经取代了很久以前安装更新中待处理的DLL。