Delete Geckodriver temp folders using Powershell

Geckodriver is an executable that interacts with Firefox installed on the System to run automated tests by running the Firefox instance either fully or in ghost-mode.
Geckodriver creates profiles in the Windows temp folder that can be of huge size depending on the Profile created for the Firefox driver.
The folder name is of the format “rust_mozprofile*”.

The following Powershell script will delete such folders by searching for this string format under C:\windows\temp and also creates logs for the deleted folders.

$datestring = (Get-Date).ToString("s").Replace(":","-")

Start-Transcript C:\logs\Mozprofile_LogPurgeTranscript_$datestring.txt -NoClobber
get-childitem -path c:\windows\temp | where{$_.LastWriteTime -lt (get-date).AddDays(-30) -and $_.name -like "rust_mozprofile*" -and $_.psiscontainer -eq $true} |Sort-Object lastwritetime -Descending| select -last 100 |% {remove-item -Recurse $_.fullname -force -Verbose -Confirm:$false}
Stop-Transcript

This PowerShell script can also be used to generally search for folders and matching a string a delete them.

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 )

Connecting to %s

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