Forum Discussion
AB21805
Jun 08, 2023Bronze Contributor
Clear cache folder from Users appdata (onenote)
Hi all I have a script which clears files in the cache folder which works if I run on the laptop manually however I cant seem to get it done via intune? Here is the script: # Define th...
I would add an exit to it..... and myabe if you want to perform the delete from the system context instead of the user , you could do something like this
detect
-------------------------
Write-Host -ForegroundColor Green "Getting the list of users"
md c:\install -force
dir C:\Users | select Name | Export-Csv -Path C:\install\users.csv -NoTypeInformation
$list=Test-Path C:\install\users.csv
Import-CSV -Path C:\install\users.csv -Header Name | foreach {
$files = get-childitem C:\Users\$($_.Name)\AppData\Local\Microsoft\OneNote\16.0\cache -Force -EA SilentlyContinue -Verbose
}
if ($files.Count -gt 0) {
Write-Output "Files found in cache directory"
Write-Output "Non-Compliant"
exit 1
}
else {
Write-Output "No files found in cache directory"
Write-Output "Compliant"
exit 0
}
remediate
-----------------
Write-Host -ForegroundColor Green "Getting the list of users"
md c:\install -force
dir C:\Users | select Name | Export-Csv -Path C:\install\users.csv -NoTypeInformation
Import-CSV -Path C:\install\users.csv -Header Name | foreach {
Remove-item C:\Users\$($_.Name)\AppData\Local\Microsoft\OneNote\16.0\cache\*.* -Force -EA SilentlyContinue -Verbose
}
detect
-------------------------
Write-Host -ForegroundColor Green "Getting the list of users"
md c:\install -force
dir C:\Users | select Name | Export-Csv -Path C:\install\users.csv -NoTypeInformation
$list=Test-Path C:\install\users.csv
Import-CSV -Path C:\install\users.csv -Header Name | foreach {
$files = get-childitem C:\Users\$($_.Name)\AppData\Local\Microsoft\OneNote\16.0\cache -Force -EA SilentlyContinue -Verbose
}
if ($files.Count -gt 0) {
Write-Output "Files found in cache directory"
Write-Output "Non-Compliant"
exit 1
}
else {
Write-Output "No files found in cache directory"
Write-Output "Compliant"
exit 0
}
remediate
-----------------
Write-Host -ForegroundColor Green "Getting the list of users"
md c:\install -force
dir C:\Users | select Name | Export-Csv -Path C:\install\users.csv -NoTypeInformation
Import-CSV -Path C:\install\users.csv -Header Name | foreach {
Remove-item C:\Users\$($_.Name)\AppData\Local\Microsoft\OneNote\16.0\cache\*.* -Force -EA SilentlyContinue -Verbose
}
AB21805
Jun 12, 2023Bronze Contributor
I will give this a go thanks Rudy, I will keep you posted.