Reputation: 103
Firstly, I am not getting the specific file where the google chrome store cookies in.
Secondly, I may think that it store in google\chrome\User Data\Default
in this path i found cookies name file. I delete the file but still google chrome contains the cookies in their browser.
So, what is the way to delete the cookies file using Powershell
so it won't appear the same cookies in browser.
Upvotes: 0
Views: 5302
Reputation: 61068
Ok, so here's my attempt to clearup Chrome history (including cookies)
function Clear-ChromeHistory {
<#
.SYNOPSIS
Removes Google Chrome history entries.
.DESCRIPTION
Removes Google Chrome history entries.
.NOTES
Author: Theo Ros
.PARAMETER DaysToKeep
Specifies the number of days to keep history. Everything older that
the given number of days (as seen from now) will be removed.
Defaults to 7
.PARAMETER Recommended
This is a shorthand switch. When set, all ArchivedHistory, BrowsingHistory,
Cookies, Favicons, MediaData and TemporaryFiles will be cleared.
FormData, Passwords and TopSites will be left alone.
.PARAMETER All
This is a shorthand switch. When set, ALL history items will be cleared.
.PARAMETER ArchivedHistory
When set, Archived History (BrowsingHistory older than 90 days) will be removed.
.PARAMETER BrowsingHistory
When set, History and History-journal and Visited Links will be removed.
.PARAMETER Cookies
When set, Cookies and Cookies-journal will be removed.
.PARAMETER Favicons
When set, Favicons and Favicons-journal will be removed.
.PARAMETER Passwords
When set, Login Data and Login Data-journal will be removed.
.PARAMETER MediaData
When set, the Media Cache will be emptied.
.PARAMETER TemporaryFiles
When set, the Temporary Cache will be emptied.
.PARAMETER TopSites
When set, Top Sites and Top Sites-journal will be removed.
.PARAMETER FormData
When set, Web Data en Web Data-journal (among others Autocomplete) will be removed.
.EXAMPLE
Clear-ChromeHistory -Recommended -DaysToKeep 14
Will remove all Recommended items older than 14 days.
.EXAMPLE
Clear-ChromeHistory -Cookies -DaysToKeep 0
Will remove all cookies.
#>
[CmdletBinding(DefaultParameterSetName = 'Recommended', ConfirmImpact = 'None')]
param (
[Parameter(Mandatory = $false, Position = 0)]
[int] $DaysToKeep = 7,
[Parameter(ParameterSetName='Recommended')]
[switch] $Recommended,
[Parameter(ParameterSetName='ByAll')]
[switch] $All,
[Parameter(ParameterSetName='ByItem')]
[switch] $ArchivedHistory, # Archived History (BrowsingHistory older than 90 days)
[Parameter(ParameterSetName='ByItem')]
[switch] $BrowsingHistory, # file: History and History-journal and Visited Links
[Parameter(ParameterSetName='ByItem')]
[switch] $Cookies, # file: Cookies and Cookies-journal
[Parameter(ParameterSetName='ByItem')]
[switch] $Favicons, # file: Favicons and Favicons-journal
[Parameter(ParameterSetName='ByItem')]
[switch] $Passwords, # file: Login Data and Login Data-journal
[Parameter(ParameterSetName='ByItem')]
[switch] $MediaData, # folder: Media Cache
[Parameter(ParameterSetName='ByItem')]
[switch] $TemporaryFiles, # folder: Cache
[Parameter(ParameterSetName='ByItem')]
[switch] $TopSites, # file: Top Sites and Top Sites-journal
[Parameter(ParameterSetName='ByItem')]
[switch] $FormData # file: Web Data en Web Data-journal (among others Autocomplete)
)
if (Get-Process -Name chrome -ErrorAction SilentlyContinue) {
Write-Warning ("Chrome process(es) are still running. Please close all before clearing the history.`r`n" +
"Use Get-Process -Name chrome -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue")
return
}
$path = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default"
if (!(Test-Path -Path $path -PathType Container)) {
Write-Error "Chrome history path '$path' not found"
return
}
if ($psCmdlet.ParameterSetName -eq 'Recommended') {
# remove all these:
$ArchivedHistory = $BrowsingHistory = $Cookies = $Favicons = $MediaData = $TemporaryFiles = $true
# but leave these intact:$FormData = $Passwords = $TopSites
= $false
}
$msg = @()
$items = @()
if ($ArchivedHistory -or $All) { $items += "Archived History*" ; $msg += "Archived History" }
if ($BrowsingHistory -or $All) { $items += @("History*", "Visited Links*") ; $msg += @("History", "Visited Links") }
if ($Cookies -or $All) { $items += "Cookies*" ; $msg += "Cookies" }
if ($Favicons -or $All) { $items += "Favicons*" ; $msg += "Favicons" }
if ($FormData -or $All) { $items += "Web Data*" ; $msg += "Form Data" }
if ($MediaData -or $All) { $items += "Media Cache*" ; $msg += "Media Cache" }
if ($Passwords -or $All) { $items += "Login Data*" ; $msg += "Passwords" }
if ($TemporaryFiles -or $All) { $items += "Cache*" ; $msg += "Temporary Files Cache" }
if ($TopSites -or $All) { $items += "Top Sites*" ; $msg += "Top Sites" }
$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
$refdate = (Get-Date).AddDays(-([Math]::Abs($DaysToKeep)))
$allItems = @()
if ($items.Length) {
$allItems += $items | ForEach-Object {
$name = $_
Get-ChildItem $path -Recurse -Force |
Where-Object { ($_.CreationTime -lt $refdate) -and $_.Name -like $name }
}
}
if ($allItems.Length) {
# type the bullet character with Alt-7
$join = "`r`n • "
$msg = ($msg | Sort-Object) -join $join
Write-Verbose ("$($MyInvocation.MyCommand):$join$msg")
$allItems | ForEach-Object { Remove-Item $_.FullName -Force -Recurse }
}
else {
Write-Verbose "$($MyInvocation.MyCommand): Nothing selected or older than $($refdate.ToString()) found"
}
$ErrorActionPreference = $oldErrorActionPreference
}
To just remove cookies and nothing else, use it like so:
Clear-ChromeHistory -DaysToKeep 1 -Cookies -Verbose
However, there are a lot more switches with which you can remove other Chrome data aswell.
Upvotes: 2