forked from jdhitsolutions/ISEScriptingGeek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTo-CommentHelp.ps1
More file actions
68 lines (58 loc) · 1.27 KB
/
ConvertTo-CommentHelp.ps1
File metadata and controls
68 lines (58 loc) · 1.27 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
#requires -version 3.0
<#
this function will make a best effort to convert help from an existing cmdlet to comment
based help. This is handy when building a proxy function.
Converted help will be opened in a new ISE Tab.
#>
Function ConvertTo-CommentHelp {
Param()
Add-Type -AssemblyName "microsoft.visualbasic" -ErrorAction Stop
$Prompt = "Enter the name of a cmdlet. Leave blank to cancel"
$Default = ""
$Title = $MyInvocation.MyCommand.Name
[string]$command = [microsoft.visualbasic.interaction]::InputBox($Prompt,$Title,$Default)
if ($command) {
Try {
$help = get-help -Name $command -full -errorAction Stop
}
Catch {
Throw $_
#bail out
Return
}
}
Else {
#cancelled
}
If ($help) {
$myHelp = @"
<#
.Synopsis
$($help.Synopsis)
.Description
$($help.description.Text)
$(foreach ($param in $help.parameters.parameter) {
".Parameter $($param.name)`n"
"$($param.Description.Text)"
"`n"
})
.Inputs
$(($help.inputTypes | out-string).trim())
.Outputs
$(($help.returnValues | out-string).trim())
.Notes
$($help.alertSet.alert | foreach {"$($_.text)`n"})
$(foreach ($item in $help.examples.example) {
".Example`n"
$($item.code)
"`n"
$(($item.remarks| out-string).trimEnd())
"`n"
})
.Link
$(($help.relatedLinks | out-string).Trim())
#>
"@
$myHelp | Out-ISETab
} #if $help
}