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.
C:\Profiles\\someName\UPM_Profile\AppData\Local\Temp\*
? Even better, instead of guessing, create a variable $itemToRemove, and use Write-Host to display each item that is removed. Writing and debugging scripts is difficult with no logging/information.Appdata\Local
is specifically designed for data that does not need to persist between sessions. Why not excludeAppData\Local
andAppData\LocalLow
in the Citrix Profile Management policy? Then you don't have to perform the cleanup in the future :)