-
Notifications
You must be signed in to change notification settings - Fork 29
/
Convert-ChocolateyToWinget.ps1
119 lines (115 loc) · 4.37 KB
/
Convert-ChocolateyToWinget.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<#
.SYNOPSIS
Change from managing various packages with Chocolatey to WinGet.
.EXAMPLE
Convert-ChocolateyToWinget.ps1 -SkipPackages autohotkey,git
Moves package management from Chocolatey to WinGet for everything except
autohotkey (maybey you are managing Adobe Digital Editions with Chocolatey),
or git (maybe you are managing PoshGit with Chocolatey).
.FUNCTIONALITY
System and updates
#>
#Requires -Version 3
#Requires -RunAsAdministrator
[CmdletBinding(ConfirmImpact='High',SupportsShouldProcess=$true)] Param(
# A specific package to convert
[Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ValueFromRemainingArguments=$true)]
[string[]] $PackageName,
# Chocolatey packages to skip.
[string[]] $SkipPackages,
# Fully uninstalls the Chocolatey package before installing the corresponding winget package,
# instead of simply removing the package from the Chocolatey package list.
[switch] $Force
)
Begin
{
$cunistparams = if($Force) {@()} else {@('-n','--skipautouninstaller')}
$packages = Data {ConvertFrom-StringData @'
7zip=7zip.7zip
ag=JFLarvoire.Ag
audacity=Audacity.Audacity
authy-desktop=Twilio.Authy
autohotkey=Lexikos.AutoHotkey
azure-cli=Microsoft.AzureCLI
azure-data-studio=Microsoft.AzureDataStudio
azure-functions-core-tools=Microsoft.AzureFunctionsCoreTools
cdburnerxp=Canneverbe.CDBurnerXP
dellcommandupdate-uwp=Dell.CommandUpdate
dotnet-sdk=Microsoft.dotnet
dotnetfx=Microsoft.dotNetFramework
dropbox=Dropbox.Dropbox
emeditor=Emurasoft.EmEditor
etcher=Balena.Etcher
firefox=Mozilla.Firefox
# winget is unable to pin packages, so specific hardware is not supported
#geforce-experience=Nvidia.GeForceExperience
gh=GitHub.cli
git=Git.Git
github=GitHub.GitHubDesktop
github-desktop=GitHub.GitHubDesktop
gitkraken=Axosoft.GitKraken
google-chrome-x64=Google.Chrome
googlechrome=Google.Chrome
googledrive=Google.Drive
googleearth=Google.EarthPro
gotomeeting=LogMeIn.GoToMeeting
gource=acaudwell.Gource
graphviz=Graphviz.Graphviz
handbrake=HandBrake.HandBrake
hdhomerun-view=Silicondust.HDHomeRunTECH
inkscape=Inkscape.Inkscape
irfanview=IrfanSkiljan.IrfanView
libreoffice=TheDocumentFoundation.LibreOffice
microsoft-edge=Microsoft.Edge
microsoft-teams=Microsoft.Teams
# winget is unable to pin packages, so versions that use incompatible OpenSSL versions would be installed
#microsoft-windows-terminal=Microsoft.WindowsTerminal
mp3tag=Mp3tag.Mp3tag
mremoteng=mRemoteNG.mRemoteNG
# winget is unable to pin packages, so versions that use incompatible OpenSSL versions would be installed
#nodejs=OpenJS.NodeJS
NSwagStudio=RicoSuter.NSwagStudio
oh-my-posh=JanDeDobbeleer.OhMyPosh
onedrive=Microsoft.OneDrive
# winget isn't as scriptable as choco for updating the shell basics
#powershell-core=Microsoft.PowerShell
powertoys=Microsoft.PowerToys
python=Python.Python.3
python3=Python.Python.3
rpi-imager=RaspberryPiFoundation.RaspberryPiImager
slack=SlackTechnologies.Slack
steam=Valve.Steam
steam-client=Valve.Steam
sumatrapdf=SumatraPDF.SumatraPDF
sumatrapdf.install=SumatraPDF.SumatraPDF
ubisoft-connect=Ubisoft.Connect
# vcredist-all is a convenient metapackage, which winget doesn't really support
visualstudio2019buildtools=Microsoft.VisualStudio.2019.BuildTools
visualstudio2022buildtools=Microsoft.VisualStudio.2022.BuildTools
vlc=VideoLAN.VLC
vlc.install=VideoLAN.VLC
vscode=Microsoft.VisualStudioCode
vscode.install=Microsoft.VisualStudioCode
vscode-insiders=Microsoft.VisualStudioCode.Insiders
vscode-insiders.install=Microsoft.VisualStudioCode.Insiders
windirstat=WinDirStat.WinDirStat
winmerge=WinMerge.WinMerge
zoom=Zoom.Zoom
'@}
}
Process
{
if(!$PackageName) {$PackageName = $packages.Keys |Sort-Object}
foreach($p in $PackageName)
{
if($p -in $SkipPackages) {Write-Verbose "Skipping Chocolatey package '$p'"; continue}
if(!$packages.ContainsKey($p)) {Write-Error "Chocolatey package '$p' has not been mapped to a WinGet package"; continue}
if(!(choco list $p -erl --idonly |Select-Object -skip 1))
{Write-Verbose "Chocolatey package '$p' not found, skipping."; continue}
if(!$PSCmdlet.ShouldProcess("Chocolatey package '$p' with WinGet package '$($packages.$p)'",'replace')) {continue}
Write-Verbose "Uninstalling Chocolatey package '$p'"
choco uninstall $p -y @cunistparams
Write-Verbose "Installing WinGet package '$($packages.$p)'"
winget install -e --id $packages.$p
}
}