Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 818
user2353132 Avatar asked Apr 16 '14 19:04

user2353132


People also ask

How do I use set-ACL in PowerShell?

To use Set-Acl , use the Path or InputObject parameter to identify the item whose security descriptor you want to change. Then, use the AclObject or SecurityDescriptor parameters to supply a security descriptor that has the values you want to apply. Set-Acl applies the security descriptor that is supplied.


1 Answers

You can set your error action preference per cmdlet like:

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

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

$ErrorActionPreference = "SilentlyContinue"

Get-Help about_CommonParameters

like image 115
Cole9350 Avatar answered Nov 12 '22 18:11

Cole9350