Made a powershell script to go into AppData\Default\Cache directory and clear it, and it works fine for the system I made it for. However this will be used with hundreds of different computers and I need some way to make the directory work with all of them.
I've tried using:
cd %AppData%
$pop = New-Object -ComObject Wscript.Shell
$num = $pop.Popup("This will close *confidential*. Are you sure?",0,"Clear Cache",0x1)
if ($num -eq 1)
{
$c = get-process -name "chrome" |stop-process -force ;
remove-item 'C:\Users\RegisterA\AppData\Local\Google\Chrome\User Data\Default\Cache' -recurse -force ;
start-process -filepath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
}
else {exit}
So as you can see this code is made for RegisterA User, but some computers will have RegisterB, RegB, StationA, etc. I need to find a way to make this work on all systems without making employees have to type in current host name.
You can retrieve that path of the local AppData folder from the LocalAppData
environment variable:
if ($num -eq 1)
{
$c = get-process -name "chrome" |stop-process -force ;
remove-item "$env:LocalAppData\Google\Chrome\User Data\Default\Cache" -recurse -force ;
start-process -filepath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
}
$env:LocalAppData
will automatically be replaced by the path to the current user's local app data folder. It's important that you use double quotes ("
) instead of single quotes ('
), otherwise the path will not be replaced.
I would also recommend replacing C:\Program Files (x86)
with $env:ProgramFiles(x86)
in the same way, since some users may have this folder at a different location.