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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With