【发布时间】:2018-09-24 11:18:53
【问题描述】:
代码:
$cPstFiles = Get-ChildItem -Path $env:USERPROFILE -File -Force `
-Recurse -Include "*.pst" -ErrorAction "SilentlyContinue"
例外:
Get-ChildItem : Access is denied
At test.ps1:172 char:22
+ $cPstFiles = Get-ChildItem -Path $env:USERPROFILE -File -Force `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand
上下文:PowerShell v4.0/.NET 4.5.2/Windows 7。
这怎么可能?我怎样才能让SilentlyContinue 做它应该做的事情?
可能值得一提的是,脚本并不总是失败。它在某些机器上失败,但在其他机器上运行良好,即使在所有这些机器上都使用相同的映像部署了 Windows。
【问题讨论】:
-
你确定 ` 后面没有空格吗?将所有参数放在一行时是否得到相同的结果
-
没有空格,将所有参数放在一行并不会改变任何东西。