I wrote the following script to delete all temp files and cached data from users profiles located on network share.
It works fine when I run it locally on my machine but when I attempt to run it on a network share it always fails.
This is how my script works,
- specify a list of folder that needs cleanup names.text
- specify the path for the directory
use remove-item command to delete the required files
$userlist = Get-Content -Path "C:\Profiles\names.txt" $home_folders = "C:\Profiles\" $UserList | ForEach-Object { $User_Home = $Home_Folders + "\" + $_ Remove-Item "$User_Home\UPM_Profile\AppData\Local\Temp\*" -Force -Recurse }
What I have done so far?
- I tried placing the path as \UNC path but that does nothing.
- I tried to remove -erroraction silentlycontinue to see what kind of errors shows up but it does nothing. like I execute the script but it just hang.
- I also tried to execute the script from the same network share but without luck.