-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathExport-InstalledPackages.ps1
More file actions
98 lines (81 loc) · 2.27 KB
/
Export-InstalledPackages.ps1
File metadata and controls
98 lines (81 loc) · 2.27 KB
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
<#
.SYNOPSIS
Exports the list of packages installed by various tools.
.FUNCTIONALITY
System and updates
.LINK
https://powershellgallery.com/
.LINK
https://manpages.debian.org/trixie/apt/apt.8.en.html
.LINK
https://pacman.archlinux.page/
.LINK
https://docs.microsoft.com/windows/package-manager/winget/
.LINK
https://chocolatey.org/
.LINK
https://scoop.sh/
.LINK
https://npmjs.com/
.LINK
https://docs.microsoft.com/dotnet/core/tools/global-tools
.LINK
https://cli.github.com/
.EXAMPLE
Export-InstalledPackages.ps1 |ConvertTo-Json |Out-File ~/installed.json utf8
Exports all known packages.
#>
#Requires -Version 7
[CmdletBinding()] Param()
function Test-Command
{
[CmdletBinding()] Param(
[Parameter(Position=0,Mandatory=$true)][string] $Name
)
return [bool](Get-Command $Name -ErrorAction Ignore)
}
$installed = @{psmodules = Get-Module -ListAvailable |Select-Object -Unique -ExpandProperty Name}
if(Test-Command apt)
{
$installed['apt'] = apt list --installed
}
if(Test-Command pacman)
{
$installed['pacman'] = pacman -Qe
}
if(Test-Command winget)
{
winget export -o "$env:TEMP\winget.json" |Out-Null
$winget = Get-Content "$env:TEMP\winget.json" |ConvertFrom-Json
$installed['winget'] = @($winget.Sources.Packages.PackageIdentifier)
}
if(Test-Command choco)
{
$installed['choco'] = @(choco list -l --idonly |Select-Object -Skip 1 |Select-Object -SkipLast 1)
}
if(Test-Command scoop)
{
$installed['scoop-buckets'] = @(scoop bucket list |Select-Object -ExpandProperty Name)
$installed['scoop'] = @(scoop list |Select-Object -ExpandProperty Name)
}
if(Test-Command npm)
{
$installed['npm'] = @(npm list -g --json |
ConvertFrom-Json -AsHashtable |
Select-Object -ExpandProperty dependencies |
Select-Object -ExpandProperty Keys)
}
if(Test-Command dotnet)
{
$installed['dotnet-tools'] = @(dotnet tool list -g |Select-Object -Skip 2 |ForEach-Object {($_ -split '\s+',2)[0]})
}
if(Test-Command gh)
{
$installed['gh-extensions'] = @(gh extension list |ForEach-Object {($_ -split '\s+',4)[2]})
}
if(Test-Command code)
{
$installed['vscode-extensions'] = @(code --list-extensions)
}
Write-Warning "The exported packages are a verbose list that will probably require editing."
return $installed