-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowModuleCommandsAndHelp.ps1
More file actions
52 lines (46 loc) · 1.66 KB
/
Copy pathshowModuleCommandsAndHelp.ps1
File metadata and controls
52 lines (46 loc) · 1.66 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
#Requires -Version 5.1
[CmdletBinding(SupportsShouldProcess=$false)]
param(
[Parameter(Mandatory=$false)] [string] $moduleName,
[Parameter(Mandatory=$false)] [ValidateSet('Basic', 'Detailed', 'Full')] [string] $helpLevel = 'Detailed'
)
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
Set-StrictMode -Version 'Latest'
if (-not (Get-Module -Name $moduleName -ListAvailable -ErrorAction SilentlyContinue)) {
Write-Error "module `"$moduleName`" not found"
return
}
$divider = [string]::new('#', 80)
function _writeDivider {
[CmdletBinding(SupportsShouldProcess=$true)]
[OutputType([void])]
param([string] $msg)
Write-Output $divider
if ($msg) {
Write-Output $msg
Write-Output $divider
}
}
_writeDivider -msg 'Module Details'
Get-Module -Name $moduleName -ListAvailable |
Select-Object -First 1 <# should we sort by version or something? Get-Command below only shows one, how does it decide which one? #> |
Format-List -Property Name,Version,Author,CompanyName,Copyright,ModuleBase,Path,Description,ProjectUri,ModuleType
_writeDivider -msg 'Module Exports'
Get-Command -Module $moduleName | Format-Table -Property @{Label='CommandType';Expression={$_.CommandType};Alignment='Left'},@{Label='Name';Expression={$_.Name};Alignment='Left'}
foreach ($cmd in (Get-Command -Module $moduleName)) {
_writeDivider -msg $cmd.Name
switch ($helpLevel) {
'Basic' {
Get-Help -Name (Join-Path $cmd.ModuleName $cmd.Name) | Out-String
break
}
'Detailed' {
Get-Help -Name (Join-Path $cmd.ModuleName $cmd.Name) -Detailed | Out-String
break
}
'Full' {
Get-Help -Name (Join-Path $cmd.ModuleName $cmd.Name) -Full | Out-String
break
}
}
}