I am trying to recursively get the files from a folder with multiple sub-folders. I noticed that Windows XP created this 5b....cb\amd64 files in the folder and it keeps throwing me the access denied error.
Get-ChildItem: Access to path is denied.
I do not have admin rights in these machines and what I am trying to do is skip these folders.
Is there a way to do this? Here is what I have tried with no success. Is it a good idea to suppress these messages as it does not break the script? Any help will be appreciated.
Get-ChildItem $sourceDir -Recurse | ? { $_.FullName -notlike '*\5b...cb\*'}
| Where-Object {$_.CreationTime.Date -eq ((Get-Date).Date)} |
foreach {
Write-Host $_
}
Get-ChildItem $sourceDir -Recurse -ErrorAction SilentlyContinue
? – Mathias R. Jessen-exclude
only works at the leaf level, so it's not useful in excluding a directory's sub-items when using-recurse
. The access denied errors is a natural filter, and Mathias's suggestion that you just ignore the errors is a good idea. – BenH