Private/Help/Get-HelpAllFunctionsFromModule.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
function Get-HelpAllFunctionsFromModule {
    <#
    .SYNOPSIS
    Gets all public functions from given module.

    .PARAMETER ModulePath
    Module path.

    .PARAMETER ModuleName
    Module name.

    .EXAMPLE
    $functionsToDocument = Get-HelpAllFunctionsFromModule -ModulePath $ModulePath -ModuleName $ModuleName
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
    [CmdletBinding()]
    [OutputType([object[]])]
    param(
        [Parameter(Mandatory=$true)]
        [string]
        $ModulePath,

        [Parameter(Mandatory=$true)]
        [string]
        $ModuleName
    )

    Write-Log -Info "Getting functions from $ModulePath"
    #Import-Module -Name $ModulePath -Force
    $allPs1Files = Get-ChildItem -Path "$modulePath\Public" -Include "*.ps1" -Recurse | Select-Object -ExpandProperty FullName

    $result = New-Object -TypeName System.Collections.ArrayList
    foreach ($ps1File in $allPs1Files) {
        Write-Host "psfile $ps1File"
        $funcName = (Split-Path -Path $ps1File -Leaf).Replace('.ps1', '')
        $cmd = Get-Command -Module $ModuleName -Name $funcName -ErrorAction SilentlyContinue
        if ($cmd) {
            $help = Get-Help -Name $funcName -ErrorAction SilentlyContinue
            [void]($result.Add([PSCustomObject]@{
                FunctionName = $funcName
                Path = $ps1File
                Command = $cmd
                Help = $help
            }))
        }
    }
    return $result.ToArray()
}