Edge chromium – Clearbrowsercache

<#
.SYNOPSIS
   This is a script for the cleanup of Edge browser cache on windows devices

.DESCRIPTION
 Clearbrowsercache

.PARAMETER  
	Default Parametername

.EXAMPLE
	powershell -executionpolicy bypass -file Clearbrowsercache.ps1

.NOTES
	NAME:		<Clearbrowsercache>
	AUTHOR:		
	KEYWORDS:	Keyword1


.CHANGE
	Author : Kamal  30/06/2023
	Version 1.0
#>
	
Function main {

## Allows the use of -WhatIf
    [CmdletBinding(SupportsShouldProcess=$True)]

param(
    ## LogFile path for the transcript to be written to
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=0)]
        $LogFile = ("C:\CMDMGMT\LOGS\"+"ClearEdgecache"+'.log'),

    ## All verbose outputs will get logged in the transcript($logFile)
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=2)]
        $VerbosePreference = "Continue",

    ## All errors should be withheld from the console
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=3)]
        $ErrorActionPreference = "SilentlyContinue"
)

    ## Begin the timer
        $Starters = (Get-Date) 
	
	 ## Check $VerbosePreference variable, and turns -Verbose on
        Function global:Write-Verbose ( [string]$Message ) {
            if ( $VerbosePreference -ne 'SilentlyContinue' ) {
                Write-Host "$Message" -ForegroundColor 'Green'
            }
        }

        Start-Transcript -Path $LogFile
        Write-Verbose "Start time: $starters"
        
    ## Check $VerbosePreference variable, and turns -Verbose on
        Function global:Write-Verbose ( [string]$Message ) {
            if ( $VerbosePreference -ne 'SilentlyContinue' ) {
                Write-Host "$Message" -ForegroundColor 'Green'
            }
        }	
        
Function ClearEdgecache {

# Stop all instances of the Microsoft Edge browser
Get-Process -Name msedge | Stop-Process -Force

$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            'Login Data',
            'Top Sites',
            'Visited Links',
            'Web Data')
$Folder = "C:\Users\*\AppData\Local\Microsoft\Edge\User Data\Default"
$Items | % { 
    if (Test-Path "$Folder\$_") {
        Remove-Item "$Folder\$_" -Recurse -Force -EA SilentlyContinue -Verbose
    }
}
}
ClearEdgecache

 ## Completed Successfully!
 Write-Host (Stop-Transcript) -ForegroundColor Green
 
}
  Main

Leave a comment