小编Ste*_*man的帖子

使用 Get-ChildItem 时如何避免 UnathorizedAccessException?

我正在使用 PowerShell 5.0 并编写一个脚本来递归地查找并列出当前目录下 log4net.dll 的所有版本。

Get-ChildItem log4net.dll -Recurse | % versioninfo | Export-Csv "C:\MyJunk\log4net.csv"
Run Code Online (Sandbox Code Playgroud)

上述语句开始按预期返回版本信息,但执行在我缺乏访问权限的第一个文件夹处停止:

Get-ChildItem : The specified network name is no longer available.
At line:1 char:1
+ Get-ChildItem log4net.dll -Recurse | % versioninfo | Export-Csv "C:\M ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ReadError: (J:\ArcPlan_OracleWallet\Production:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access is denied
At line:1 char:1
+ Get-ChildItem log4net.dll -Recurse | % versioninfo | Export-Csv "C:\M ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-ChildItem], …
Run Code Online (Sandbox Code Playgroud)

powershell get-childitem

5
推荐指数
1
解决办法
6618
查看次数

标签 统计

get-childitem ×1

powershell ×1