【问题标题】:Powershell script to omit traversing access denied folders from a list of foldersPowershell 脚本从文件夹列表中省略遍历访问被拒绝的文件夹
【发布时间】:2014-04-16 19:59:53
【问题描述】:

我正在尝试编写一个脚本来列出提取文件夹和子文件夹以及特定目录路径的文件数。如何排除脚本中拒绝访问的文件夹?

我使用get-childitem 代码sn-p 和where {$_.permission -match "read",我不知道我尝试的是否正确。我最终得到以下错误:消息:

CategoryInfo : ReadError: (\support....-242\New folder:String) [Get-ChildItem], IOException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

【问题讨论】:

    标签: powershell powershell-2.0 powershell-3.0


    【解决方案1】:

    您可以为每个 cmdlet 设置错误操作首选项,例如:

    Get-ChildItem -recurse -ErrorAction SilentlyContinue | ? {$_.permission -match "read"}
    

    或者您可以使用系统变量为每个脚本设置它:

    $ErrorActionPreference = "SilentlyContinue"

    Get-Help about_CommonParameters

    【讨论】:

    • 感谢您的回复,我真的很喜欢这篇文章,它帮助我解决了我的疑问。非常感谢。
    • 我继续进行:“get-childitem -recurse -ErrorAction SilentlyContinue | ? {$_.permission -match "read"}
    猜你喜欢
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多