forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-CommandSyntax.ps1
More file actions
54 lines (48 loc) · 1.77 KB
/
Get-CommandSyntax.ps1
File metadata and controls
54 lines (48 loc) · 1.77 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
Function Get-CommandSyntax {
[cmdletbinding()]
[alias("gsyn")]
[outputtype("System.String")]
Param(
[Parameter(
Position = 0,
Mandatory,
HelpMessage = "Enter the name of a PowerShell cmdlet or function. Ideally it has been loaded into the current PowerShell session."
)]
[ValidateScript({ Get-Command -Name $_ })]
[string]$Name
)
Write-Verbose "Starting $($MyInvocation.mycommand)"
foreach ($provider in (Get-PSProvider)) {
Write-Verbose "Testing with the $($provider.name) Provider"
if ($host.name -match "console") {
"$([char]0x1b)[1;4;38;5;155m$($provider.name)$([char]0x1b)[0m"
}
else {
$provider.name
}
#get first drive
$path = "$($provider.drives[0]):\"
Write-Verbose "..getting syntax"
Push-Location
Set-Location $path
$syn = Get-Command -Name $Name -Syntax | Out-String
Write-Verbose "..getting dynamic parameters"
$get = Get-Command -Name $name
$dynamic = ($get.parameters.GetEnumerator() | Where-Object { $_.value.IsDynamic }).key
Pop-Location
if ($dynamic) {
Write-Verbose "...found $($dynamic.count) dynamic parameters"
Write-Verbose "...$($dynamic -join ",")"
foreach ($param in $dynamic) {
if ($host.name -match 'console') {
$syn = $syn -replace "\b$param\b", "$([char]0x1b)[1;38;5;213m$param$([char]0x1b)[0m"
}
else {
#must be in the PowerShell ISE so don't use any ANSI formatting
}
}
}
$syn
} #foreach Provider
Write-Verbose "Ending $($MyInvocation.mycommand)"
}