[英]Powershell script to omit traversing access denied folders from a list of folders
我試圖做一個腳本來列出提取文件夾和子文件夾以及特定目錄路徑的文件數。 如何排除腳本中拒絕訪問的文件夾?
我使用了get-childitem
代碼片段以及where {$_.permission -match "read"
,我不知道我嘗試的是否正確。 我最終得到以下錯誤:消息:
CategoryInfo:ReadError:(\\ support ....- 242 \\ New folder:String)[Get-ChildItem],IOException + FullyQualifiedErrorId:DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
您可以為每個cmdlet設置錯誤操作首選項,如:
Get-ChildItem -recurse -ErrorAction SilentlyContinue | ? {$_.permission -match "read"}
或者您可以使用System變量為每個腳本設置它:
$ErrorActionPreference = "SilentlyContinue"
Get-Help about_CommonParameters
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.