-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateHelpFile.ps1
More file actions
163 lines (135 loc) · 4.19 KB
/
Copy pathCreateHelpFile.ps1
File metadata and controls
163 lines (135 loc) · 4.19 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True,Position=0)]
[string]$Cmdlet,
[Parameter(Mandatory=$True,Position=1)]
[string]$Destination
)
$CmdletInfo = Get-Command $Cmdlet
$HelpInfo = Get-Help $Cmdlet
$Output = @()
# Header
$Output += "# $($CmdletInfo.Name)"
$Output += ""
# Synopsis
$Output += "## Synopsis"
$Output += ""
$Output += $Helpinfo.Synopsis
$Output += ""
# Syntax
$Output += "## Syntax"
$Output += ""
$i = 0
foreach ($Set in $CmdletInfo.ParameterSets) {
# need to limit line lenght to 90 char
$SetName = $Set.Name
if ($Set.IsDefault) {
$SetName += " (Default)"
}
if ($SetName -notmatch "__AllParameterSets") {
$Output += "### $SetName"
}
$Output += ""
$Syntax = $HelpInfo.syntax.syntaxItem[$i].parameter
$SyntaxString = ""
$SyntaxString += $CmdletInfo.Name + " "
foreach ($Parameter in $Syntax) {
$ParamString = ""
if ($Parameter.parameterValue) {
$ParameterValue = "<" + $Parameter.parameterValue + ">"
} else {
$ParameterValue = $null
}
Write-Verbose "ParameterValue: $ParameterValue"
if ($Parameter.position -eq 'named') {
$ParameterName = "-" + $Parameter.name
} else {
$ParameterName = "[-" + $Parameter.name + "]"
}
if ($Parameter.required -eq $true) {
Write-Verbose "Is Required"
$ParameterString = $ParameterName
if ($ParameterValue.Length -gt 0) {
Write-Verbose "ParameterValue present"
$ParameterString += " " + $ParameterValue
}
} else {
Write-Verbose "Is Not Required"
$ParameterString = "[" + $ParameterName
if ($ParameterValue) {
$ParameterString += " " + $ParameterValue
}
$ParameterString += "]"
}
$ParameterString += " "
$SyntaxString += $ParameterString
}
$Output += '```powershell'
$Output += $SyntaxString
$Output += '```'
$Output += ''
$i++
}
# Description
$Output += "## Description"
$Output += ''
$Output += $HelpInfo.description.text
$Output += ''
# Examples
$Output += "## Examples"
$Output += ''
$Examples = $HelpInfo.examples.example
$e = 1
foreach ($Example in $Examples) {
$ExampleString = @()
$ExampleString += "### Example $e"
$ExampleString += ""
$ExampleString += '```'
$ExampleString += "PS c:\> $($Example.Code)"
$ExampleString += '```'
$ExampleString += ""
$ExampleString += $Example.remarks
$ExampleString += ""
$Output += $ExampleString
$e++
}
# Parameters
$Output += "## Parameters"
$Output += ''
$ParameterSetCount = $Cmdletinfo.ParameterSets.Count
$Parameters = $HelpInfo.parameters.parameter
foreach ($Parameter in $Parameters) {
$ParameterString = @()
# Name
$ParameterString += "### -$($Parameter.Name)"
$ParameterString += ""
# Description
$ParameterString += $Parameter.description.text
$ParameterString += ""
# ParameterSet Lookup
$ParameterLookup = $CmdletInfo.ParameterSets | Where-Object { $_.Parameters.name -contains $Parameter.Name }
if ($ParameterLookup.Count -eq $ParameterSetCount) {
$ParameterSetString = "All"
} else {
$ParameterSetString = $ParameterLookup.name -join ", "
}
# Cmdlet Lookup
$CmdletLookup = $CmdletInfo.Parameters."$($Parameter.Name)"
$Aliases = $CmdletLookup.Aliases -join ", "
# Properties
$ParameterString += '```asciidoc'
$ParameterString += "Type: " + $Parameter.type.name
$ParameterString += "Parameter Sets: " + $ParameterSetString
$ParameterString += "Aliases: " + $Aliases
$ParameterString += ""
$ParameterString += "Required: " + $Parameter.required
$ParameterString += "Position: " + $Parameter.position
$ParameterString += "Default value: " + $Parameter.defaultValue
$ParameterString += "Accept pipeline input: " + $Parameter.pipelineInput
$ParameterString += "Accept wildcard characters: " + $Parameter.globbing
$ParameterString += '```'
$Output += $ParameterString
}
# Output File
$global:OutTest = $Output
$Output | Out-File $Destination -Encoding ascii