Downloads:
1,096,469
Downloads of v 1.1.1:
348,502
Last Update:
26 Jun 2023
Package Maintainer(s):
Software Author(s):
- bcurran3
Tags:
bcurran3 unofficial choco cleaner cleanup schtasks scheduled task(unofficial) Choco Cleaner (Script + Task)
- 1
- 2
- 3
1.1.1 | Updated: 26 Jun 2023
Downloads:
1,096,469
Downloads of v 1.1.1:
348,502
Maintainer(s):
Software Author(s):
- bcurran3
(unofficial) Choco Cleaner (Script + Task) 1.1.1
Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by bcurran3. The inclusion of bcurran3 trademark(s), if any, upon this webpage is solely to identify bcurran3 goods or services and not for commercial purposes.
- 1
- 2
- 3
All Checks are Passing
3 Passing Tests
Deployment Method: Individual Install, Upgrade, & Uninstall
To install (unofficial) Choco Cleaner (Script + Task), run the following command from the command line or from PowerShell:
To upgrade (unofficial) Choco Cleaner (Script + Task), run the following command from the command line or from PowerShell:
To uninstall (unofficial) Choco Cleaner (Script + Task), run the following command from the command line or from PowerShell:
Deployment Method:
This applies to both open source and commercial editions of Chocolatey.
1. Enter Your Internal Repository Url
(this should look similar to https://community.chocolatey.org/api/v2/)
2. Setup Your Environment
1. Ensure you are set for organizational deployment
Please see the organizational deployment guide
2. Get the package into your environment
Option 1: Cached Package (Unreliable, Requires Internet - Same As Community)-
Open Source or Commercial:
- Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
- You can also just download the package and push it to a repository Download
-
Open Source
-
Download the package:
Download - Follow manual internalization instructions
-
-
Package Internalizer (C4B)
-
Run: (additional options)
choco download choco-cleaner --internalize --source=https://community.chocolatey.org/api/v2/
-
For package and dependencies run:
choco push --source="'INTERNAL REPO URL'"
- Automate package internalization
-
Run: (additional options)
3. Copy Your Script
choco upgrade choco-cleaner -y --source="'INTERNAL REPO URL'" [other options]
See options you can pass to upgrade.
See best practices for scripting.
Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.
If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:
choco upgrade choco-cleaner -y --source="'INTERNAL REPO URL'"
$exitCode = $LASTEXITCODE
Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
Exit 0
}
Exit $exitCode
- name: Install choco-cleaner
win_chocolatey:
name: choco-cleaner
version: '1.1.1'
source: INTERNAL REPO URL
state: present
See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.
chocolatey_package 'choco-cleaner' do
action :install
source 'INTERNAL REPO URL'
version '1.1.1'
end
See docs at https://docs.chef.io/resource_chocolatey_package.html.
cChocoPackageInstaller choco-cleaner
{
Name = "choco-cleaner"
Version = "1.1.1"
Source = "INTERNAL REPO URL"
}
Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.
package { 'choco-cleaner':
ensure => '1.1.1',
provider => 'chocolatey',
source => 'INTERNAL REPO URL',
}
Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.
4. If applicable - Chocolatey configuration/installation
See infrastructure management matrix for Chocolatey configuration elements and examples.
This package was approved by moderator Windos on 27 Jun 2023.
choco://choco-cleaner
To use choco:// protocol URLs, install (unofficial) choco:// Protocol support
DO YOU WANT TO RECOVER SOME DISK SPACE USED BY UNNECESSARY RESIDUAL CHOCOLATEY FILES?
YOU JUST FOUND THE EASY WAY!
This package creates a Windows Scheduled Task to run Choco-Cleaner.ps1 every Sunday at 11:00 PM.
BEFORE and AFTER Choco-Cleaner: (198 packages installed and does not include temp folder deletions.)
Sure, you're probably not going to get gigabytes of space back, but every few KB matters on some computers and to some people! Due to slack space small files such as 6 byte .ignore files actually take up 4 KB of HDD space each.
FEATURES:
Set it and forget it! Choco-Cleaner cleans up your Chocolatey installation every Sunday at 11 PM in the background so you don't have to be bothered with it.
Choco-Cleaner is completely configurable, just run Choco-Cleaner -EditConfig and read the comments. Most options are enabled by default.
Choco-Cleaner deletes:
- .log files that are not the most current one (NOT default)
- .zip and various archive files left over from packages that forgot to delete them post install
- .zip.txt and other archive-extensions.txt are lists of files that were extracted from an archive file for installation (NOT default)
- .msi, .msu, and .msp are Microsoft intall packages left over from packages that forgot to delete them post install
- .ignore files that are created to not shim executables during package install but not needed after shim operations are finished (This may change in a future version of Chocolatey.)
- credits.txt are program credits (of contributors) files you can read on the web
- readme.txt files you can read on the web
- .md files are usually markdown readme files that you can read on the web
- .old files are Chocolatey files that have been replaced by newer versions (exe's and dll's mostly)
- chocolatey.config.backup is a backup of your chocolatey.config file
- _processed.txt - I have no idea what made this file or why it exists
- lib-bad holds packages that failed to install and lib-bkp contains previous package versions during upgrades
- lib-synced holds packages installed by the (licensed versions) choco sync feature (NOT default)
- archives and executables out of .nupkg files which are ZIP archives with NuGet package information - this is similar to what Package Reducer does
- \users\username\AppData\Local\Temp\chocolatey is where new package files are downloaded to during pre-installation (if you haven't changed your cacheLocation in chocolatey.config)
- files in cacheLocation if set in chocolatey.config
- \users\username\AppData\Local\Nuget\Cache if Nuget client is installed and caching files there
- \Windows\Temp\chocolatey
- license.txt and verification.txt files are included when packages include binaries, you can read them on the package web page, programname.license.txt files are license files for Chocolatey default tools (NOT default)
- orphaned shim files for programs that no longer exist
- orphaned package install snapshot files found in the .chocolatey folder
If you find Choco-Cleaner useful, and I suspect you will, please consider donating: https://www.paypal.me/bcurran3donations or become a patron at https://www.patreon.com/bcurran3
<?xml version="1.0"?>
<Settings>
<Preferences>
<DeleteLicenseFiles>FALSE</DeleteLicenseFiles>
<DeleteLogs>FALSE</DeleteLogs>
<DeleteFileLogs>FALSE</DeleteFileLogs>
<DeleteArchives>TRUE</DeleteArchives>
<DeleteMSInstallers>TRUE</DeleteMSInstallers>
<DeleteIgnoreFiles>TRUE</DeleteIgnoreFiles>
<DeleteReadmes>TRUE</DeleteReadmes>
<DeleteOldChoco>TRUE</DeleteOldChoco>
<DeleteConfigBackupFile>TRUE</DeleteConfigBackupFile>
<DeleteLibBad>TRUE</DeleteLibBad>
<DeleteLibBkp>TRUE</DeleteLibBkp>
<Optimizenupkg>TRUE</Optimizenupkg>
<DeleteCache>TRUE</DeleteCache>
<DeleteNuGetCache>TRUE</DeleteNuGetCache>
<DeleteBadShims>TRUE</DeleteBadShims>
<DeleteDotChocolatey>TRUE</DeleteDotChocolatey>
<DeleteLibSynced>FALSE</DeleteLibSynced>
</Preferences>
</Settings>
<!--
#######################################################################################################################
# You can toggle any above feature by setting it TRUE/FALSE
#
# LEGEND:
# DeleteLicenseFiles
# - deletes license.txt and verification.txt files found when packages include binaries
# DeleteLogs
# - deletes .log files that are not the most current one
# DeleteFileLogs
# - deletes .zip.txt and other archive-extensions.txt are lists of files that were extracted from an archive file during installation
# DeleteArchives
# - deletes .zip, .rar, .iso, and various archive files left over from packages that forgot to delete them after install
# DeleteMSInstallers
# - deletes .msi, .msu, and .msp (Microsoft intall packages) left over from packages that forgot to delete them after install
# DeleteIgnoreFiles
# - deletes .ignore files created to not shim executables during package install but not needed after shim operations are finished (This may change in a # future version of Chocolatey.)
# DeleteReadmes
# - deletes readme.txt, credits.txt, and *.md files
# DeleteOldChoco
# - deletes .old Chocolatey files that have been replaced by newer versions (exe's and dll's mostly)
# DeleteConfigBackupFile
# - deletes chocolatey.config.backup
# DeleteLibBad
# - deletes lib-bad folder where packages that failed to install go to die
# DeleteLibBkp
# - deletes lib-bkp folder where old packages that have been updated go to die
# Optimizenupkg
# - deletes archives and executables out of .nuspkg files - this is similar to what [Package Reducer](https://chocolatey.org/docs/features-package-reducer) does
# DeleteCache
# - deletes cached Chocolatey downloaded package files
# DeleteNuGetCache
# - deletes cached NuGet downloaded package files
# DeleteBadShims
# - deletes bad/old Chocolatey shim files
# DeleteDotChocolatey
# - deletes old Chocolatey package install snapshot files from $env:ChocolateyInstall\.chocolatey
# DeleteLibSynced
# - deletes lib-synced folder where Chocolatey (licensed) puts packages related to [choco sync](https://docs.chocolatey.org/en-us/features/package-synchronization/sync-command) feature
#######################################################################################################################
-->
$ErrorActionPreference = 'Continue'
#Requires -RunAsAdministrator
# Choco-Cleaner.ps1 Copyleft 2017-2023 by Bill Curran AKA BCURRAN3
# LICENSE: GNU GPL v3 - https://www.gnu.org/licenses/gpl.html
# Suggestions? Problems? Open a GitHub issue at https://github.com/bcurran3/ChocolateyPackages/issues
Write-Host "Choco-Cleaner.ps1 v1.1.1 (2023-06-26) - deletes unnecessary residual Chocolatey files to free up disk space" -Foreground White
Write-Host "Copyleft 2017-2023 Bill Curran ([email protected]) - free for personal and commercial use`n" -Foreground White
# Verify ChocolateyToolsLocation was created by Get-ToolsLocation during install and is in the environment
if (!($ENV:ChocolateyToolsLocation)) {$ENV:ChocolateyToolsLocation = "$ENV:SystemDrive\tools"}
if (!(Test-Path "$ENV:ChocolateyToolsLocation\BCURRAN3")) {Write-Warning "Configuration file not found. Please re-install."; throw}
# Set Notepad++ as preferred editor/viewer
if (Test-Path $ENV:ChocolateyInstall\bin\notepad++.exe){
$Editor="notepad++.exe"
}else {
$Editor="notepad.exe"
}
# Easily edit the config file
if ($args -eq "-EditConfig"){
Write-Host " ** Editing contents of choco-cleaner.config." -Foreground Magenta
&$Editor "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.config"
return
}
# Easily view the log file
if ($args -eq "-ViewLog"){
Write-Host " ** Showing contents of choco-cleaner.log." -Foreground Magenta
&$Editor "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
return
}
##### VARIABLES BEGIN
# All 7Zip supported formats plus EXE, MSU, MSP, APPX, APPXBUNDLE, IMG - Is anything else needed?
$BinaryExtensions=@(
"*.exe","*.img","*.msu","*.msp","*.appx","*.appxbundle","*.7z","*.xz",
"*.bzip2","*.gzip","*.tar","*.zip","*.wim","*.ar","*.arj","*.cab","*.chm",
"*.cpio","*.cramfs","*.dmg","*.ext","*.fat","*.gpt","*.hfs","*.ihex",
"*.iso","*.lzh","*.lzma","*.mbr","*.msi","*.nsis","*.ntfs","*.qcow2",
"*.rar","*.rpm","*.squashfs","*.udf","*.uefi","*.vdi","*.vhd","*.vmdk",
"*.xar","*.z","*.dll"
)
# All log file types
$file_log_types = @(
"*.zip.txt","*.exe.txt","*.rar.txt","*.7z.txt","*.gz.txt","*.tar.txt",
"*.sfx.txt","*.iso.txt"
)
# All temporary archive types
$archive_types = @(
"*.zip","*.rar","*.7z","*.gz","*.tar","*.sfx","*.iso","*.img","*.appx",
"*.appxbundle","*.bzip2","*.gzip","*.tar","*.lzh","*.z"
)
# All license text types
$license_types = @( "license.txt","*.license.txt","verification.txt" )
# All embedded installer types
$embed_types = @( "*.msi","*.msu","*.msp" )
# All readme types
$readme_types = @( "credits.txt","readme.txt","*.md" )
# global tracking and reporting variables
$global:CCExitCode=0
$global:global:DeletedFiles=0
$global:PermissionErrors=$False
$global:Reclaimed=0
# Import preferences from choco-cleaner.config
[xml]$ConfigFile = Get-Content "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.config"
if ($ConfigFile.Settings.Preferences.DeleteLogs -eq "true") {$DeleteLogs=$True} else {$DeleteLogs=$False}
if ($ConfigFile.Settings.Preferences.DeleteArchives -eq "true") {$DeleteArchives=$True} else {$DeleteArchives=$False}
if ($ConfigFile.Settings.Preferences.DeleteFileLogs -eq "true") {$DeleteFileLogs=$True} else {$DeleteFileLogs=$False}
if ($ConfigFile.Settings.Preferences.DeleteMSInstallers -eq "true") {$DeleteMSInstallers=$True} else {$DeleteMSInstallers=$False}
if ($ConfigFile.Settings.Preferences.DeleteIgnoreFiles -eq "true") {$DeleteIgnoreFiles=$True} else {$DeleteIgnoreFiles=$False}
if ($ConfigFile.Settings.Preferences.DeleteReadmes -eq "true") {$DeleteReadmes=$True} else {$DeleteReadmes=$False}
if ($ConfigFile.Settings.Preferences.DeleteOldChoco -eq "true") {$DeleteOldChoco=$True} else {$DeleteOldChoco=$False}
if ($ConfigFile.Settings.Preferences.DeleteConfigBackupFile -eq "true") {$DeleteConfigBackupFile=$True} else {$DeleteConfigBackupFile=$False}
if ($ConfigFile.Settings.Preferences.DeleteLibBad -eq "true") {$DeleteLibBad=$True} else {$DeleteLibBad=$False}
if ($ConfigFile.Settings.Preferences.DeleteLibBkp -eq "true") {$DeleteLibBkp=$True} else {$DeleteLibBkp=$False}
if ($ConfigFile.Settings.Preferences.DeleteLibSynced -eq "true") {$DeleteLibSynced=$True} else {$DeleteLibSynced=$False}
if ($ConfigFile.Settings.Preferences.Optimizenupkg -eq "true") {$Optimizenupkg=$True} else {$Optimizenupkg=$False}
if ($ConfigFile.Settings.Preferences.DeleteCache -eq "true") {$DeleteCache=$True} else {$DeleteCache=$False}
if ($ConfigFile.Settings.Preferences.DeleteLicenseFiles -eq "true") {$DeleteLicenseFiles=$True} else {$DeleteLicenseFiles=$False}
if ($ConfigFile.Settings.Preferences.DeleteNuGetCache -eq "true") {$DeleteNuGetCache=$True} else {$DeleteNuGetCache=$False}
if ($ConfigFile.Settings.Preferences.DeleteBadShims -eq "true") {$DeleteBadShims=$True} else {$DeleteBadShims=$False}
if ($ConfigFile.Settings.Preferences.DeleteDotChocolatey -eq "true") {$DeleteDotChocolatey=$True} else {$DeleteDotChocolatey=$False}
# Import chocolatey.config and get cacheLocation if set
[xml]$ChocoConfigFile = Get-Content "$ENV:ChocolateyInstall\config\chocolatey.config"
$cacheLocation = $ChocoConfigFile.chocolatey.config | ForEach-Object { $_.add } | Where-Object { $_.key -eq 'cacheLocation' } | Select-Object -Expand value
##### VARIABLES END
##### HELPER FUNCTIONS BEGIN
# add to log file
function Add2Log {
Param ( [string]$comment )
Write-Output "$(Get-Date) [INFO ] $comment" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
}
# add to log file and display error
function Add2LogError {
Param ( [string]$comment )
Write-Host " ** [ERROR] $comment" -Foreground Red
Write-Output "$(Get-Date) [ERROR] $comment" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
$global:CCExitCode=1
}
# run shim and report if the target program exists or not
function Test-ShimTargetExists {
Param ( [Object][Parameter(Mandatory=$true, ValueFromPipeline=$true)]$ShimFile )
$TargetExists = & "$ShimFile" "--shimgen-help" |
Select-String -pattern "Target Exists: 'True'"
if (-not $TargetExists) {
Return $false
} else {
Return $true
}
}
##### HELPER FUNCTIONS END
##### MAIN FUNCTIONS BEGIN
# Deletes _processed.txt
function DelProcessedTxt {
if (Test-Path $ENV:ChocolateyInstall\bin\_processed.txt){
Write-Host " ** Deleting unnecessary Chocolatey _processed.txt (WTF?) file..." -Foreground Green
Remove-Item -Path $ENV:ChocolateyInstall\bin\_processed.txt -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey _processed.txt file due to permissions."
} else {
$global:global:DeletedFiles=$global:global:DeletedFiles + 1
}
}
}
# Deletes .ignore files
function DeleteIgnoreFiles {
$IgnoreFilesSize=0
$GotIgnoreFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\lib -Recurse -Include *.ignore -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$IgnoreFiles=$GotIgnoreFiles.count
if ($IgnoreFiles -ge 1){
Write-Host " ** Deleting $IgnoreFiles unnecessary Chocolatey .ignore files..." -Foreground Green
$GotIgnoreFiles | ForEach-Object {$IgnoreFilesSize=$IgnoreFilesSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall -Recurse -Include *.ignore -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey .ignore files due to permissions."
} else {
$GotIgnoreFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $IgnoreFilesSize bytes"
$global:global:DeletedFiles=$global:global:DeletedFiles + $IgnoreFiles
$global:Reclaimed=$global:Reclaimed + $IgnoreFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey .ignore files to delete." -Foreground Green
}
}
# Deletes Chocolatey .old files
function DeleteOldChoco {
$GotOldChocoSize=0
$GotOldChoco=Get-ChildItem -Path $ENV:ChocolateyInstall -Recurse -Include *.old -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$OldChoco=$GotOldChoco.count
if ($OldChoco -ge 1){
Write-Host " ** Deleting $OldChoco unnecessary Chocolatey .old files..." -Foreground Green
$GotOldChoco | ForEach-Object {$GotOldChocoSize=$GotOldChocoSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall -Recurse -Include *.old -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting Chocolatey .old files due to permissions."
} else {
$GotOldChoco.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotOldChocoSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $OldChoco
$global:Reclaimed=$global:Reclaimed + $GotOldChocoSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey .old files to delete." -Foreground Green
}
}
# Deletes Chocolatey cache files in multiple locations
function DeleteCache {
$UserDirs=Get-ChildItem -Path C:\Users -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
for ($Count = 0; $Count -lt $UserDirs.FullName.Count; $Count++){
$GotCacheFilesSize=0
$dir = $userdirs.fullname[$Count]
$dir = "$dir" + "\appdata\local\temp\chocolatey"
$GotCacheFiles=Get-ChildItem -Path $dir -Recurse -ErrorAction SilentlyContinue
$CacheFiles=$GotCacheFiles.count
if ($CacheFiles -ge 1){
Write-Host " ** Deleting $CacheFiles unnecessary Chocolatey cache files ($dir)..." -Foreground Green
$GotCacheFiles | ForEach-Object {$GotCacheFilesSize=$GotCacheFilesSize + $_.length}
Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey cache files ($dir) due to permissions."
} else {
$GotCacheFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotCacheFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $CacheFiles
$global:Reclaimed=$global:Reclaimed + $GotCacheFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey cache files ($dir) to delete." -Foreground Green
}
}
$GotCacheFiles=Get-ChildItem -Path $ENV:SystemRoot\temp\chocolatey -Recurse -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$CacheFiles=$GotCacheFiles.count
if ($CacheFiles -ge 1){
$GotCacheFilesSize=0
Write-Host " ** Deleting $CacheFiles unnecessary Chocolatey cache files ($ENV:SystemRoot\temp\chocolatey)..." -Foreground Green
$GotCacheFiles | ForEach-Object {$GotCacheFilesSize=$GotCacheFilesSize + $_.length}
Remove-Item -Path $ENV:SystemRoot\temp\chocolatey -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey cache files ($ENV:SystemRoot\temp\chocolatey) due to permissions."
} else {
$GotCacheFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotCacheFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $CacheFiles
$global:Reclaimed=$global:Reclaimed + $GotCacheFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey cache files ($ENV:SystemRoot\temp\chocolatey) to delete." -Foreground Green
}
if ($cacheLocation){
$GotCacheFilesSize=0
if (Test-Path $cacheLocation) {
$GotCacheFiles=Get-ChildItem -Path $cacheLocation -Recurse -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$CacheFiles=$GotCacheFiles.count
if ($CacheFiles -ge 1){
Write-Host " ** Deleting $CacheFiles unnecessary Chocolatey cache files ($cacheLocation)..." -Foreground Green
$GotCacheFiles | ForEach-Object {$GotCacheFilesSize=$GotCacheFilesSize + $_.length}
Remove-Item -Path $GotCacheFiles.fullname -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey cache files ($cacheLocation) due to permissions."
} else {
$GotCacheFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotCacheFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $CacheFiles
$global:Reclaimed=$global:Reclaimed + $GotCacheFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey cache files ($cacheLocation) to delete." -Foreground Green
}
}
}
}
# Deletes NuGet cache files
function DeleteNuGetCache {
$UserDirs=Get-ChildItem -Path C:\Users -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
for ($Count = 0; $Count -lt $UserDirs.FullName.Count; $Count++){
$GotNuGetCacheSize=0
$dir = $userdirs.fullname[$Count]
$dir = "$dir" + "\appdata\Local\Nuget\Cache"
$GotNuGetCache=Get-ChildItem -Path $dir -Recurse -ErrorAction SilentlyContinue
$NuGetCache=$GotNuGetCache.count
if ($NuGetCache -ge 1){
Write-Host " ** Deleting $NuGetCache unnecessary Nuget cache files ($dir)..." -Foreground Green
$GotNuGetCache | ForEach-Object {$GotNuGetCacheSize=$GotNuGetCacheSize + $_.length}
Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Nuget cache files ($dir) due to permissions."
} else {
$GotNuGetCache.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotNuGetCacheSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $NuGetCache
$global:Reclaimed=$global:Reclaimed + $GotNuGetCacheSize
}
} else {
Write-Host " ** NO unnecessary Nuget cache files ($dir) to delete." -Foreground Green
}
}
}
# Deletes chocolatey.config.backup
function DeleteConfigBackupFile {
if (Test-Path $ENV:ChocolateyInstall\config\chocolatey.config.backup){
Write-Host " ** Deleting unnecessary Chocolatey config backup file..." -Foreground Green
Remove-Item -Path $ENV:ChocolateyInstall\config\chocolatey.config.backup -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey config backup file due to permissions."
} else {
Add2Log "DELETED: $ENV:ChocolateyInstall\config\chocolatey.config.backup"
$global:DeletedFiles=$global:DeletedFiles + 1
}
} else {
Write-Host " ** NO unnecessary Chocolatey config backup file to delete." -Foreground Green
}
}
# Deletes files in lib-bad
function DeleteLibBad {
$GotLibBadFilesSize=0
if (Test-Path $ENV:ChocolateyInstall\lib-bad){
$GotLibBadFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\lib-bad -Recurse
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$LibBadFiles=$GotLibBadFiles.count
if ($LibBadFiles -ge 1){
Write-Host " ** Deleting $LibBadFiles unnecessary Chocolatey lib-bad package files..." -Foreground Green
$GotLibBadFiles | ForEach-Object {$GotLibBadFilesSize=$GotLibBadFilesSize + $_.length}
Remove-Item -Path $GotLibBadFiles.fullname -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey lib-bad files due to permissions."
} else {
$GotLibBadFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotLibBadFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $LibBadFiles
$global:Reclaimed=$global:Reclaimed + $GotLibBadFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey lib-bad package files to delete." -Foreground Green
}
}
}
# Deletes files in lib-bkp
function DeleteLibBkp {
$GotLibBkpFilesSize=0
if (Test-Path $ENV:ChocolateyInstall\lib-bkp){
$GotLibBkpFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\lib-bkp -Recurse
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$LibBkpFiles=$GotLibBkpFiles.count
if ($LibBkpFiles -ge 1){
Write-Host " ** Deleting $LibBkpFiles unnecessary Chocolatey lib-bkp package files..." -Foreground Green
$GotLibBkpFiles | ForEach-Object {$GotLibBkpFilesSize=$GotLibBkpFilesSize + $_.length}
Remove-Item -Path $GotLibBkpFiles.fullname -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey lib-bkp files due to permissions."
} else {
$GotLibBkpFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotLibBkpFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $LibBkpFiles
$global:Reclaimed=$global:Reclaimed + $GotLibBkpFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey lib-bkp package files to delete." -Foreground Green
}
}
}
# Deletes files in lib-synced
function DeleteLibSynced {
$GotLibSyncedFilesSize=0
if (Test-Path $ENV:ChocolateyInstall\lib-synced){
$GotLibSyncedFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\lib-synced -Recurse
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$LibSyncedFiles=$GotLibSyncedFiles.count
if ($LibSyncedFiles -ge 1){
Write-Host " ** Deleting $LibSyncedFiles unnecessary Chocolatey lib-synced package files..." -Foreground Green
$GotLibSyncedFiles | ForEach-Object {$GotLibSyncedFilesSize=$GotLibSyncedFilesSize + $_.length}
Remove-Item -Path $GotLibSyncedFiles.fullname -Recurse -Force -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey lib-synced files due to permissions."
} else {
$GotLibSyncedFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotLibSyncedFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $LibSyncedFiles
$global:Reclaimed=$global:Reclaimed + $GotLibSyncedFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey lib-synced package files to delete." -Foreground Green
}
}
}
# Deletes files in the hidden .chocolatey directory
function DeleteDotChocolatey {
$deltaSize=0
#if (([System.Version]([System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:chocolateyinstall\choco.exe").ProductVersion)).major -gt 1) {
if ([System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:chocolateyinstall\choco.exe").ProductMajorPart -gt 1){
$InstalledPackages = & choco list -r -y
} else {
$InstalledPackages = & choco list -lo -r -y
}
$InstalledPackages=$InstalledPackages.replace("|",".")
$DotChocolateyDirs = Get-ChildItem -Path $env:ChocolateyInstall\.chocolatey\* -Directory -Name
$delta = $DotChocolateyDirs | Where-Object {$InstalledPackages -NotContains $_}
$DotChocolateyFiles2Delete=$delta | foreach-object $_ {Get-ChildItem -Path $env:ChocolateyInstall\.chocolatey\$_}
$DeltaCount=$DotChocolateyFiles2Delete.count
if ($DeltaCount -ge 1){
Write-Host " ** Deleting $DeltaCount unnecessary Chocolatey .chocolatey install snapshot files..." -Foreground Green
$DotChocolateyFiles2Delete | ForEach-Object {$deltaSize=$deltaSize + $_.length}
Remove-Item $DotChocolateyFiles2Delete.fullname -Recurse -Force # Deletes files but not empty directories
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting .chocolatey install snapshot files due to permissions."
} else {
$delta | % {Remove-Item $env:ChocolateyInstall\.chocolatey\$_ -Recurse -Force}
$DotChocolateyFiles2Delete.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $deltaSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $DeltaCount
$global:Reclaimed=$global:Reclaimed + $deltaSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey .chocolatey install snapshot files to delete." -Foreground Green
}
}
# Deletes package install file logs
function DeleteFileLogs {
$GotFileLogsSize=0
$GotFileLogs=Get-ChildItem -Path $ENV:ChocolateyInstall -Recurse -Include $file_log_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$FileLogs=$GotFileLogs.count
if ($FileLogs -ge 1){
Write-Host " ** Deleting $FileLogs unnecessary Chocolatey extracted file logs..." -Foreground Green
$GotFileLogs | ForEach-Object {$GotFileLogsSize=$GotFileLogsSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall -Recurse -Include $file_log_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey extracted file logs due to permissions."
} else {
$GotFileLogs.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotFileLogsSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $FileLogs
$global:Reclaimed=$global:Reclaimed + $GotFileLogsSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey extracted file logs to delete." -Foreground Green
}
}
# Deletes Chocolatey logs except the most recent one
function DeleteLogs {
$GotOldLogsSize=0
$GotOldLogs=Get-ChildItem -Path $ENV:ChocolateyInstall\logs\*.log -Recurse -Exclude chocolatey.log,choco.summary.log -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$FileLogs=$GotOldLogs.count
if ($FileLogs -ge 1){
Write-Host " ** Deleting $FileLogs unnecessary Chocolatey log files..." -Foreground Green
$GotOldLogs | ForEach-Object {$GotOldLogsSize=$GotOldLogsSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall\logs\*.log -Exclude chocolatey.log,choco.summary.log -Recurse -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey log files due to permissions."
} else {
$GotOldLogs.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotOldLogsSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $FileLogs
$global:Reclaimed=$global:Reclaimed + $GotOldLogsSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey log files to delete." -Foreground Green
}
}
# Deletes archive files left over from package installs
function DeleteArchives {
$GotArchvieFilesSize=0
$GotArchvieFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\lib -Recurse -Include $archive_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$ArchiveFiles=$GotArchvieFiles.count
if ($ArchiveFiles -ge 1){
Write-Host " ** Deleting $ArchiveFiles unnecessary Chocolatey package embedded archive files in toolsDirs..." -Foreground Green
$GotArchvieFiles | ForEach-Object {$GotArchvieFilesSize=$GotArchvieFilesSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall\lib -Recurse -Include $archive_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey package embedded archive files due to permissions."
} else {
$GotArchvieFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotArchvieFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $ArchiveFiles
$global:Reclaimed=$global:Reclaimed + $GotArchvieFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey package embedded archive files in toolsDirs to delete." -Foreground Green
}
}
# Deletes embedded archives and executables out of package files
function Optimizenupkg {
$nupkgsSizeBefore=0
$nupkgsSizeAfter=0
$Gotnupkgs=(Get-Childitem $ENV:ChocolateyInstall\lib -Recurse -Include *.nupkg -ErrorAction SilentlyContinue)
$Gotnupkgs | ForEach-Object {$nupkgsSizeBefore=$nupkgsSizeBefore + $_.length}
Write-Host " ** Deleting unnecessary Chocolatey package embedded archives and executables in .nupkg files..." -Foreground Green
$Gotnupkgs | ForEach-Object {
& $ENV:ChocolateyInstall\tools\7z.exe d -r -tZIP $_ $BinaryExtensions | Out-Null
if ($LASTEXITCODE) {Add2LogError "optimizing $_"}
}
$Gotnupkgs=(Get-Childitem $ENV:ChocolateyInstall\lib -Recurse -Include *.nupkg -ErrorAction SilentlyContinue)
$Gotnupkgs | ForEach-Object {$nupkgsSizeAfter=$nupkgsSizeAfter + $_.length}
$nupkgsSpaceFreed=($nupkgsSizeBefore - $nupkgsSizeAfter)
if ($nupkgsSpaceFreed -gt 0) {
Add2Log "RECLAIMED: $nupkgsSpaceFreed bytes"
$global:Reclaimed=$global:Reclaimed + $nupkgsSpaceFreed
}
}
# Deletes license files
function DeleteLicenseFiles {
$GotLicenseFilesSize=0
$GotLicenseFiles=Get-ChildItem -Path $ENV:ChocolateyInstall\* -Recurse -Include $license_types -Exclude shimgen.license.txt -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$LicenseFiles=$GotLicenseFiles.count
if ($LicenseFiles -ge 1){
Write-Host " ** Deleting $LicenseFiles unnecessary Chocolatey package embedded license files..." -Foreground Green
$GotLicenseFiles | ForEach-Object {$GotLicenseFilesSize=$GotLicenseFilesSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall -Recurse -Include $license_types -Exclude shimgen.license.txt -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey package embedded license files due to permissions."
} else {
$GotLicenseFiles.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotLicenseFilesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $LicenseFiles
$global:Reclaimed=$global:Reclaimed + $GotLicenseFilesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey package embedded license files to delete." -Foreground Green
}
}
# Deletes MS Installer files from package installs
function DeleteMSInstallers {
$GotMSInstallersSize=0
$GotMSInstallers=Get-ChildItem -Path $ENV:ChocolateyInstall\lib -Recurse -Include $embed_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$MSInstallers=$GotMSInstallers.count
if ($MSInstallers -ge 1){
Write-Host " ** Deleting $MSInstallers unnecessary Chocolatey package embedded Microsoft installers..." -Foreground Green
$GotMSInstallers | ForEach-Object {$GotMSInstallersSize=$GotMSInstallersSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall\lib -Recurse -Include $embed_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey package embedded Microsoft installer files due to permissions."
} else {
$GotMSInstallers.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotMSInstallersSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $MSInstallers
$global:Reclaimed=$global:Reclaimed + $GotMSInstallersSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey package embedded Microsoft installers to delete." -Foreground Green
}
}
# Deletes read me files from package installs
function DeleteReadmes {
$GotReadmesSize=0
$GotReadmes=Get-ChildItem -Path $ENV:ChocolateyInstall\* -Recurse -Include $readme_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
$ErrorPath=$error[0].categoryinfo.targetname
Add2LogError "reading $ErrorPath due to permissions."
}
$Readmes=$GotReadmes.count
if ($Readmes -ge 1){
Write-Host " ** Deleting $Readmes unnecessary Chocolatey package embedded various read me files..." -Foreground Green
$GotReadmes | ForEach-Object {$GotReadmesSize=$GotReadmesSize + $_.length}
Remove-Item -Path $ENV:ChocolateyInstall\* -Recurse -Include $readme_types -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey package embedded various read me files due to permissions."
} else {
$GotReadmes.fullname | ForEach-Object {Add2Log "DELETED: $_"}
Add2Log "RECLAIMED: $GotReadmesSize bytes"
$global:DeletedFiles=$global:DeletedFiles + $Readmes
$global:Reclaimed=$global:Reclaimed + $GotReadmesSize
}
} else {
Write-Host " ** NO unnecessary Chocolatey package embedded various read me files to delete." -Foreground Green
}
}
# Deletes shims that point to programs that have been uninstalled
function DeleteBadShims {
$BadShimCount=0
$ShimsSizeBefore=0
$ShimsSizeAfter=0
Write-Host " ** Checking shim files..." -NoNewline -Foreground Green
$GotShims=(Get-ChildItem $ENV:ChocolateyInstall\bin\*.exe -ErrorAction SilentlyContinue)
$GotShims | ForEach-Object {$ShimsSizeBefore=$ShimsSizeBefore + $_.length}
$GotShims | ForEach-Object {
if (-not (Test-ShimTargetExists $PSItem -ErrorAction SilentlyContinue) ){
$BadShimCount = $BadShimCount +1
Remove-Item "$PSItem" | Out-Null -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {
$global:PermissionErrors=$True
Add2LogError "deleting unnecessary Chocolatey orphaned shim files due to permissions."
} else {
Add2Log "DELETED: $PSItem"
}
}
}
Write-Host "`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b `b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b`b" -NoNewLine
if ($BadShimCount){
Write-Host " ** Deleted $BadShimCount unnecessary Chocolatey orphaned shim files..." -Foreground Green
$GotShims=(Get-ChildItem $ENV:ChocolateyInstall\bin\*.exe -ErrorAction SilentlyContinue)
$GotShims | ForEach-Object {$ShimsSizeAfter=$ShimsSizeAfter + $_.length}
$ShimSizeDeleted=($ShimsSizeBefore - $ShimsSizeAfter)
Add2Log "RECLAIMED: $ShimSizeDeleted bytes"
$global:DeletedFiles=$global:DeletedFiles + $BadShimCount
$global:Reclaimed=$global:Reclaimed + ($ShimsSizeBefore - $ShimsSizeAfter)
} else {
Write-Host " ** NO unnecessary Chocolatey orphaned shim files to delete." -Foreground Green
}
}
##### MAIN FUNCTIONS END
##### BEGIN PROCESSING
# Start logging
if (Test-Path "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"){
$LogSize=(Get-ChildItem -Path "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log").length
if ($LogSize -gt 51200){
Remove-Item "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log" -ErrorAction SilentlyContinue
if ($error[0].categoryinfo.category -match "PermissionDenied") {$global:PermissionErrors=$True}
Write-Output "$(Get-Date) Choco-Cleaner Deleted log file" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
}
}
Write-Output "----------------------------------------------------------------------" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
Write-Output "$(Get-Date) Choco-Cleaner STARTED" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
Write-Host "Choco-Cleaner Summary:" -Foreground Magenta
# Begin cleaning
DelProcessedTxt
Add2Log "CONFIG: DeleteIgnoreFiles is set to $DeleteIgnoreFiles"
if ($DeleteIgnoreFiles) {DeleteIgnoreFiles}
Add2Log "CONFIG: DeleteOldChoco is set to $DeleteOldChoco"
if ($DeleteOldChoco) {DeleteOldChoco}
Add2Log "CONFIG: DeleteCache is set to $DeleteCache"
if ($DeleteCache) {DeleteCache}
Add2Log "CONFIG: DeleteNuGetCache is set to $DeleteNuGetCache"
if ($DeleteNuGetCache) {DeleteNuGetCache}
Add2Log "CONFIG: DeleteConfigBackupFile is set to $DeleteConfigBackupFile"
if ($DeleteConfigBackupFile) {DeleteConfigBackupFile}
Add2Log "CONFIG: DeleteLibBad is set to $DeleteLibBad"
if ($DeleteLibBad) {DeleteLibBad}
Add2Log "CONFIG: DeleteLibBkp is set to $DeleteLibBkp"
if ($DeleteLibBkp) {DeleteLibBkp}
Add2Log "CONFIG: DeleteLibSynced is set to $DeleteLibSynced"
if ($DeleteLibSynced) {DeleteLibSynced}
Add2Log "CONFIG: DeleteDotChocolatey is set to $DeleteDotChocolatey"
if ($DeleteDotChocolatey) {DeleteDotChocolatey}
Add2Log "CONFIG: DeleteFileLogs is set to $DeleteFileLogs"
if ($DeleteFileLogs) {DeleteFileLogs}
Add2Log "CONFIG: DeleteLogs is set to $DeleteLogs"
if ($DeleteLogs) {DeleteLogs}
Add2Log "CONFIG: DeleteArchives is set to $DeleteArchives"
if ($DeleteArchives) {DeleteArchives}
Add2Log "CONFIG: Optimizenupkg is set to $Optimizenupkg"
if ($Optimizenupkg) {Optimizenupkg}
Add2Log "CONFIG: DeleteLicenseFiles is set to $DeleteLicenseFiles"
if ($DeleteLicenseFiles) {DeleteLicenseFiles}
Add2Log "CONFIG: DeleteMSInstallers is set to $DeleteMSInstallers"
if ($DeleteMSInstallers) {DeleteMSInstallers}
Add2Log "CONFIG: DeleteReadmes is set to $DeleteReadmes"
if ($DeleteReadmes) {DeleteReadmes}
Add2Log "CONFIG: DeleteBadShims is set to $DeleteBadShims"
if ($DeleteBadShims) {DeleteBadShims}
# Summary report
if ($global:PermissionErrors) {Write-Host " ** Some files not deleted due to permission problems." -Foreground Yellow}
$global:Reclaimed=$global:Reclaimed/1KB
$global:Reclaimed = $global:Reclaimed.ToString('N0')
Write-Host "Choco-Cleaner finished deleting $global:DeletedFiles unnecessary Chocolatey files and reclaimed ~ $global:Reclaimed KB!`n" -Foreground Magenta
Write-Output "$(Get-Date) Choco-Cleaner FINISHED and reclaimed ~ $global:Reclaimed KB!" >> "$ENV:ChocolateyToolsLocation\BCURRAN3\choco-cleaner.log"
Write-Host "Found Choco-Cleaner.ps1 useful?" -ForegroundColor White
Write-Host "Buy me a beer at https://www.paypal.me/bcurran3donations" -ForegroundColor White
Write-Host "Become a patron at https://www.patreon.com/bcurran3" -ForegroundColor White
Start-Sleep -s 10
exit $global:CCExitCode
$ErrorActionPreference = 'Stop'
$packageName = 'choco-cleaner'
$scriptDir = "$(Get-ToolsLocation)\BCURRAN3"
$shortcutName = 'Choco Cleaner.lnk'
$altshortcutName = 'Chocolatey Cleaner.lnk'
$ErrorActionPreference = 'SilentlyContinue'
$GotTask = (&schtasks /query /tn choco-cleaner) 2> $null
$ErrorActionPreference = 'Stop'
if ($GotTask) {SchTasks /Delete /TN “choco-cleaner” /F}
Remove-Item "$ENV:ProgramData\Microsoft\Windows\Start Menu\Programs\$shortcutName" -Force -ErrorAction SilentlyContinue
Remove-Item "$ENV:ProgramData\Microsoft\Windows\Start Menu\Programs\$altshortcutName" -Force -ErrorAction SilentlyContinue
Remove-Item "$ENV:ProgramData\Microsoft\Windows\Start Menu\Programs\Chocolatey\$shortcutName" -Force -ErrorAction SilentlyContinue
Remove-Item "$ENV:ChocolateyInstall\bin\choco-cleaner.bat" -Force -ErrorAction SilentlyContinue
Remove-Item "$scriptDir\choco-cleaner.*" -Force -ErrorAction SilentlyContinue | Out-Null
$CTL=Get-ToolsLocation
if (!(Get-ChildItem -Path "$CTL\BCURRAN3" | Measure-Object | %{$_.Count})) {
$ENV:Path.Replace("$CTL\BCURRAN3","") | Out-Null
Remove-Item "$CTL\BCURRAN3" | Out-Null
}
Log in or click on link to see number of positives.
- choco-cleaner.1.1.1.nupkg (b6e8a5879b25) - ## / 63
In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).
Chocolatey Pro provides runtime protection from possible malware.
Copyleft Bill Curran
INSTALL EXAMPLES:
- choco install choco-cleaner - (default) installs Choco-Cleaner to run every Sunday at 11:00 PM
- choco install choco-cleaner --params "'/NOTASK:TRUE'" - installs Choco-Cleaner without the scheduled task.
INSTRUCTIONS:
To manually run Choco-Cleaner:
- Command Prompt or PowerShell: choco-cleaner
- Windows Start Menu: click the icon. If you have choco-shortcuts-winconfig installed you'll find it with the rest of the Chocolatey Shortcuts.
If you have a previous release of Choco-Cleaner installed, upgrading to a new version will NOT modify your current preferences.
11:00 PM was chosen as not to conflict with default installs of choco-upgrade-all-at, choco-persistent-packages, and choco-optimize-at.
Organizations with software license compliance auditing should probably NOT delete the license and verification files for legal protection. The supplied configuration file defaults to false for these types of files. As ferventcoder/Rob has said many times, corporations are not advised to use the community repository and should be using Chocolatey for Business with their own internalized local packages.
SUGGESTION/RECOMMENDATION:
If you are using choco-upgrade-all-at or choco-upgrade-all-at-startup, run Choco-Upgrade-All -EditConfig and set choco-cleaner as your PostProcessScript and delete the scheduled task.
CHANGELOG:
- 1.1.1 - DeleteDotChocolatey now compatible with Chocolatey alpha/beta/delta/epsilon/zeta/eta/theta/iota/kappa/lambda/mu/nu/xi/omicron/pi/rho/sigma/tau/upsilon/phi/chi/psi/omega versions. No longer changes directory to .chocolatey when using DeleteDotChocolatey.
- 1.1.0 - Chocolatey v2 compatible - due to the breaking change to the choco list command in Chocolatey v2, all files in .chocolatey get deleted when DeleteDotChocolatey feature is enabled. CC now checks the Chocolatey version and uses the appropriate choco list command depending on version.
- 1.0.0 - v1.0 full feature release, all goals achieved! (The crowd roars... or is that just the sound of loud crickets?) You wanted Choco-Cleaner to delete the unnecessary files in the .chocolatey dir - you got it! now can delete files in lib-synced (opt-in), legend in config file got a much needed re-write (You won't see it/get it on upgrades.), no longer deletes .ignore files in Chocolatey program dirs as choco.exe regenerates 11 .ignore files EVERY time it runs now, changed log size from 4K to 50K due to increase in logging, "features" are now PS functions, now returns an exit code of 1 when there are errors
- 0.0.9.0 - now recursively deletes chocolatey and Nuget cache files from all user profiles, added more error reporting, changed log size from 1K to 4K, added -ViewLog option
- 0.0.8.5 - variable, spacing, and syntax cleanup by slycordinator, variables moved to top by Linux User
- 0.0.8.4 - Fix exception when $FreedSpace is less than zero thanks to kborowinski - Thanks!
- 0.0.8.3 - Fixed the reclaimed space calculation display thanks to salsifis - Thanks!
- 0.0.8.2 - "Psycological Phix" - I hate seeing a negative number "reclaimed" after running Choco-Cleaner due to other programs writing to disk while CC is running; e.g. downloads. So until such time as I accurately track the space of deleted files... if the result is negative, it'll now display zero. Like I said, only a psychological fix.
- 0.0.8.1 - Fixed v0.0.6 - v0.0.8 bug using unavailable environmental variable for scheduled task execution. Added small amount of logging.
- 0.0.8 - Added checking and deleting of orphaned shim files thanks to TheCakeIsNaOH and Teknowledgist! New icon thanks to Teknowledgist. Added parameter to install without scheduled task. Added -EditConfig option to easily edit the config file.
- 0.0.7.2 - Better error handling when $env:ChocolateyToolsLocation is not defined. (Usually due to running under a different account than installed from.)
- 0.0.7.1 - Added checking to make sure that $env:ChocolateyToolsLocation exists. If you receive a "$env:ChocolateyToolsLocation not defined error message," you might simply need to close your CLI and reopen it if $env:ChocolateyToolsLocation was created during choco-cleaner's install.
- 0.0.7 - Added some info about what and what isn't being deleted, added Requires -RunAsAdministrator statement to script (PS v4+)
- 0.0.6 - Fixed long standing bug where the config options set to false were ignored. Now works from Command Prompt as well as PowerShell. Additional 7Zip supported archives deleted.
- 0.0.5.2 - minor update to delete .img (alternate .iso name), and .msi,.msu, and .msp files in toolsDir, as well as minor cosmetic changes
- 0.0.5.1 - made PowerShell Core compatible
- 0.0.5 - added deletion of cacheLocation if defined in chocolatey.config, cosmetic changes, removed 7Zip dependency and now using the version of 7Zip packaged with Chocolatey.
- 0.0.4 - added deletion of Nuget Cache folder files
- 0.0.3.1 - fixed typo causing nupkg files to NOT be optimized - thanks E.R.!
- 0.0.3 - Rewritten version of 0.0.1 with XML configuration file and ferventcoder/Rob's approved default settings. Minor improvements.
- 0.0.2 - Unreleased version with two scripts with different default settings; "Bill's way" and "Rob's way" and a package parameter to choose which one to use/install. Shelved.
- 0.0.1 - Initial release. Did not pass Chocolatey moderation due to mandated changes of default parameters. Only "secretly" available.
ROADMAP:
- Feature complete. Nothing planned. If you have a suggestion, click https://github.com/bcurran3/ChocolateyPackages/issues
-
- chocolatey-core.extension (≥ 1.1.0)
Ground Rules:
- This discussion is only about (unofficial) Choco Cleaner (Script + Task) and the (unofficial) Choco Cleaner (Script + Task) package. If you have feedback for Chocolatey, please contact the Google Group.
- This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
- The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
- Tell us what you love about the package or (unofficial) Choco Cleaner (Script + Task), or tell us what needs improvement.
- Share your experiences with the package, or extra configuration or gotchas that you've found.
- If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.