Functions/Get-ModuleHelp.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
function Get-ModuleHelp {
<#
    .Synopsis
        Get help information for a specific module or a list of imported and available modules
    .DESCRIPTION
         
    .PARAMETER Name
        Mudule name.
    .PARAMETER CommandName
        Name of command in modules
    .NOTES
        Author: Jack Olsson
#>

[CmdletBinding()]
param(
    [string]$Name,
    [string]$CommandName,
    [switch]$Detail
)   

    If ([string]::IsNullOrEmpty($Name)) {
        "`nAvailable modules"
        "-----------------"
        #List installed Modules
        Get-InstalledModule | Select-Object Name, Version, Description

        #Get current active modules
        "`nImported modules"
        "----------------"
        Get-Module | Select-Object Name, Version, ModuleType

        
    } else {
        Get-Module | Where-Object {$_.Name -like "*$name*"} | ForEach-Object {            
            $module = $_
            "`n" + $module.Name
            "".PadRight(($module.Name).Length,'=')

            If ($module.ExportedWorkflows.Count -gt 0) {
                "`nWorkflows"
                "----------"
                ($module.ExportedWorkflows).Values
            }

            If ($module.ExportedDscResources.Count -gt 0) {
                "`nDsc Resources"
                "--------------"
                $module.ExportedDscResources
            }

            If ($module.ExportedVariables.Count -gt 0) {
                "`nVariables"
                "----------"
                $module.ExportedVariables
            }
            If ($module.ExportedTypeFiles.Count -gt 0) {
                "`nType Files"
                "-----------"
                $module.ExportedTypeFiles
            }

            If ($module.ExportedFormatFiles.Count -gt 0) {
                "`nFormat files"
                "-------------"
                $module.ExportedFormatFiles
            }
            If ($module.ExportedCommands.Count -gt 0) {
                "`nCommands"
                "--------"
                ($module.ExportedCommands).Values |Select-Object Name,CommandType,Version
            }
            If ($module.ExportedAliases.Count -gt 0) {                        
                "`nAliases"
                "-------"
                $aliases = $module.ExportedAliases
                $aliases.Keys | ForEach-Object {
                    $aliases[$_].Name + " -> " + $aliases[$_].Definition
                }
            }
            

        }
        

    }

}