I have the test script below that I am working on that dies when it gets to the System Volume Information folder with error shown at the bottom. I know that it is this folder because I can put a test file right before and right after it and it finds the one before but not the one right after. Why is it having a problem getting past this folder?
Second question: If I started up PS under the system account and point this script to c:\users, it still gets access denied when trying to access user profile folders. I would have thought running under the system account that it would be able to read what is in those folders. Any ideas why it can't read the contents of the folders?
Test script:
$intDaysOld = '-' + 30
$strFileType = 'bat'
$path = "c:\users"
Get-ChildItem -path "c:\" -recurse -include "*.bat" -force -ErrorAction continue | where {$_.LastWriteTime -le ((get-date).AddDays($intDaysOld).ToShortDateString())} | Remove-Item -WhatIf
Unexpected error:
Get-ChildItem : Access is denied
At line:5 char:1
+ Get-ChildItem -path "c:\" -recurse -include "*.bat" -force -ErrorAction continue ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand