Eat the cookie! – ADFS – Powershell

So tired of getting problems with ADFS cookies, so decided to find an easier way than IE to clear my local cookies using a script. This script works on Windows 10. The script should work on lower versions of Windows, however cookie extension might be different as well as location of the cookies.

# Location of IE Cookies
$Path = $env:USERPROFILE + "\AppData\Local\Microsoft\Windows\INetCookies"
$Text = '<domain name of cookie>'
$PathArray = @()

# Cookies are stored as .cookie files.
$cookies = Get-ChildItem $Path -Recurse -Force -Filter "*.cookie" 
      ForEach($cookie in $cookies)
	{
        $IsCookie=$cookie | Select-String -Pattern $Text
 	$PathArray +=$Iscookie
      	}
$Unique=$PathArray | ForEach-Object {$_.Path} | Get-Unique
$Unique | Remove-Item

Updated 11-June-2018
Improved finding the right cookie.
Change extension from .txt to .cookie

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.