Powershell script to omit traversing access denied folders from a list of folders

Question:

I was trying to do a script to list extract the folders and subfolders and the number of files for a particular path of directory. How to exclude the folders whose access is denied in the script?

I used the get-childitem code snippet along with where {$_.permission -match "read", I don’t know if what I am trying is correct or not. I ended up with the following error:message:

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

Answer:

You can set your error action preference per cmdlet like:

Or you can set it per script using the System variable:

$ErrorActionPreference = "SilentlyContinue"

Get-Help about_CommonParameters

Source:

Powershell script to omit traversing access denied folders from a list of folders by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply