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.
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.