Trying to Delete C:\Users\appdata\local\Temp\*.*

I am trying to Delete C:\Users\Username\appdata\local\Temp*.*.

The following only works for my account. I am building the script so this is only testing. I get a listing for my profile and a failure for the Public profile because the directory doesn’t exist. But I don’t get squat for any other profiles. This is on a Windows 10 computer but I would like it to work on Windows 7 also.

Get-ChildItem "C:\Users" | ForEach-Object {Get-ChildItem (Set-Location "C:\Users\$($_.name)\appdata\local\temp")}

This is a security issue, not a PowerShell issue per say. By default, a users profile only has the following permissions:

SYSTEM
(owning user)
Administrators

Now the local Administrators group is a well-known protected group, so if you’re UAC is enabled, then you will not have that permission and thus access will be denied. Test your script with administrator access (right-click run as administrator) to confirm, or look at the path permissions to validate.

Of course it does not exist. The PUBLIC profile does not have an AppData folder. Simply explude the PUBLIC directory like this:

Get-ChildItem ‘C:\Users’ -Exclude ‘PUBLIC’ |
ForEach-Object {Get-ChildItem (Set-Location “C:\Users$($_.name)\appdata\local\temp”)}

Justin,
the folders marked as system or hidden will be listed only with the parameter -Force anyway. So that does not matter in this case. :wink: