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...
AB21805
Jun 12, 2023Bronze Contributor
Yes, I did using logged in credentials. I ideally need this run everyday.
I have tried doing it as a script with devices but as user log in details and as a remediation script
Please help!
I have tried doing it as a script with devices but as user log in details and as a remediation script
Please help!
Jun 12, 2023
AB21805 You can run it as remediation script every day for the logged in user, but do you have a detection script to trigger it?
- AB21805Jun 12, 2023Bronze ContributorYes I do however the script comes back as "without Issues" so that is why I tried the actual script via scripts instead to see if it works however it doesnt but it works if I run the script manually on the devices.
Detection script:
# Define the path to the cache directory
$cachePath = "C:\Users\$env:USERNAME\AppData\Local\Microsoft\OneNote\16.0\cache"
# Check if there are any files in the cache directory
$files = Get-ChildItem -Path $cachePath -File
if ($files.Count -gt 0) {
Write-Output "Files found in cache directory"
Write-Output "Non-Compliant"
}
else {
Write-Output "No files found in cache directory"
Write-Output "Compliant"
}- Jun 12, 2023I 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
}- AB21805Jun 12, 2023Bronze ContributorI will give this a go thanks Rudy, I will keep you posted.