-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-Modules.ps1
45 lines (37 loc) · 1.29 KB
/
Get-Modules.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
function Get-Modules {
<#
.SYNOPSIS
Retrieves a list of installed PowerShell modules.
.DESCRIPTION
Easily manage PowerShell modules you installed by json file.
.EXAMPLE
> Get-Modules -output
Output modules information into modules.lock.json file in dotfiles directory.
.EXAMPLE
> Get-Modules -list
Print modules information on the console.
#>
[CmdletBinding()]
param(
[switch]$output,
[switch]$list
)
if ($PSBoundParameters.Count -eq 0) {
$result = Get-InstalledModule | Select-Object Name, Version, Author, InstalledDate, Description | Format-Table -AutoSize
}
if ($output) {
$result = Get-InstalledModule |
Select-Object Name, Version, Author, InstalledDate, Description |
ConvertTo-Json -Depth 100 |
Out-File "$Env:DOTFILES\modules.lock.json" -Encoding utf8 -Force
}
if ($list) {
if (Test-Path "$Env:DOTFILES\modules.lock.json") {
$result = Get-Content "$Env:DOTFILES\modules.lock.json" | ConvertFrom-Json | Format-Table -AutoSize
}
else {
$result = Get-InstalledModule | Select-Object Name, Version, Author, InstalledDate, Description | Format-Table -AutoSize
}
}
return $result
}