Skip to content

Instantly share code, notes, and snippets.

@RReverser
Last active April 7, 2024 18:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RReverser/efa63788a193ef8011b09e1d1d6692d5 to your computer and use it in GitHub Desktop.
Save RReverser/efa63788a193ef8011b09e1d1d6692d5 to your computer and use it in GitHub Desktop.
choco list --limit-output
# Extract name and find corresponding winget package
| ForEach-Object -Parallel {
$chocoName = $_.Split('|')[0]
Get-WinGetPackage $chocoName -Count 1 |% {
@{
'chocoName' = $chocoName
'wingetPackage' = $_.Name
}
}
}
# This part can't be parallelised as it requires user interaction.
|% {
Write-Output "Chocolatey package $($_.chocoName) is installed."
Write-Output "Winget package $($_.wingetPackage) looks like a match."
$confirmation = Read-Host "Do you want to delete Chocolatey package?"
if ($confirmation.ToUpper() -eq "Y") {
# Remove the package from Chocolatey without actually uninstalling.
choco uninstall "$($_.chocoName)" --skip-powershell --skip-autouninstaller --limit-output
}
}
# Old version that used to list WinGet packages and search in Chocolatey instead:
# Sometimes it might find more matches.
#
# Get-WinGetPackage
# # Search for matches in parallel - this doesn't require user interaction, so can be sped up significantly.
# | ForEach-Object -Parallel {
# $wingetPackage = $_.Name
# $chocolateyPackageInfo = choco list --yes --by-id-only "$wingetPackage" --limit-output
# if ($chocolateyPackageInfo) {
# return @{
# 'wingetPackage' = $wingetPackage
# 'chocolateyPackageInfo' = $chocolateyPackageInfo
# }
# }
# else {
# return $null
# }
# }
# | Where-Object { $_ }
# # Only pause to ask the user & uninstall the package when there are matches.
# | ForEach-Object {
# $wingetPackage = $_.wingetPackage
# $chocolateyPackageInfo = $_.chocolateyPackageInfo
# Write-Output "Chocolatey package $chocolateyPackageInfo is installed."
# Write-Output "Winget package $wingetPackage is available."
# $confirmation = Read-Host "Do you want to delete Chocolatey package?"
# if ($confirmation -eq "Y" -or $confirmation -eq "y") {
# $chocoName = ($chocolateyPackageInfo -split '\|')[0]
# # Remove the package from Chocolatey without actually uninstalling.
# choco uninstall "$chocoName" --skip-powershell --skip-autouninstaller --limit-output
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment