Deleting cookies based on last modified time

Version 1

    Verified Product Versions

    AppSense Environment Manager 10.0AppSense Environment Manager 8.6AppSense Environment Manager 10.1

    Introduction

    In certain scenarios, you may wish to remove files when they have not been modified for x number of days or weeks. One example of this would be when you are using a Windows Settings Group to capture Internet Explorer cookies. These can build up substantially over time so you need to find a method to manage the number of files that are synchronized to the Personalization database.

     

    Detail

    As you may know, Environment Manager Policy runs before Personalization during logoff. This means that you can utilize an Environment Manager Policy 'Custom Action' to delete files from the real file system during logoff before the Windows Settings Group syncs up the data to the database.

     

    Below is a sample PowerShell script that will remove cookies older than 5 days from two locations. This sample script is appropriate for Windows 8.x and Server 2012 (including R2).

     

    # Script to remove cookies on Win 8/2012 older than 5 days
    
    # Set folders and days to keep
    $inetFolder = "$env:LOCALAPPDATA\Microsoft\Windows\INETCookies"
    $inetLowFolder = "$env:LOCALAPPDATA\Microsoft\Windows\INetCookies\Low"
    $limit = (Get-Date).AddDays(-5)
    
    # Delete the files
    Get-ChildItem -Path $inetFolder -File | Where { $_.LastWriteTime -lt $limit } | Remove-Item -Force
    Get-ChildItem -Path $inetLowFolder -File | Where { $_.LastWriteTime -lt $limit } | Remove-Item -Force
    

     

    Obviously this script can be modified to delete other folders or keep more files if required.

     

    NOTE: From Environment Manager 10.1 onwards, a new "is older than" condition can be set on file and folder delete actions. This effectively means you do not need to use a script / custom action to perform the deletes.

    Please see below a screenshot of the new condition that is available: