Forum Discussion

AB21805's avatar
AB21805
Bronze Contributor
Jun 08, 2023

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 the path to the cache directory

$cachePath = "C:\Users\$env:USERNAME\AppData\Local\Microsoft\OneNote\16.0\cache"

 

# Get all files and folders in the cache directory

$items = Get-ChildItem -Path $cachePath -Force -Recurse

 

# Iterate through each item

foreach ($item in $items) {

    # Check if it's a file or a directory

    if ($item.PSIsContainer) {

        # Remove the directory and all its contents

        Remove-Item -Path $item.FullName -Force -Recurse

    } else {

        # Remove the file

        Remove-Item -Path $item.FullName -Force

    }

}

 

 

    • AB21805's avatar
      AB21805
      Bronze 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!
      • 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?

Resources