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...
Jun 09, 2023
AB21805 How are you deploying it? As a script within devices? (Devices - Microsoft Intune admin center) ? And did you select "Run this script using the logged on credentials" ?
- AB21805Jun 12, 2023Bronze ContributorYes, 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!- 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"
}