Created
July 6, 2017 14:42
-
-
Save Xainey/2e89de9f0e31696a4afa93f134f9c629 to your computer and use it in GitHub Desktop.
Easy to read function arguments from Get-Help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ColoredSyntax ($command) | |
{ | |
Write-Host ("{0} " -f (get-help $command).name) -NoNewline -ForegroundColor White | |
$syn = ((get-help $command).syntax.syntaxitem.parameter) | select name, @{Name='type'; Expression = {$_.type.name}}, required | |
$width = 170 | |
if ($host.UI.RawUI.WindowSize.Width -notin ("", $null)) { | |
$width = $host.UI.RawUI.WindowSize.Width | |
} | |
$curLength = 0 | |
foreach($parm in $syn) { | |
Write-Host "[" -NoNewline # +1 | |
if ($parm.required -eq $true) { | |
Write-Host ("-{0}" -f $parm.name) -NoNewline -ForegroundColor Green # +1x | |
Write-Host "]" -NoNewline # +1 | |
Write-Host (" <{0}> " -f $parm.type) -NoNewline -ForegroundColor Yellow # +4x | |
} | |
else { | |
Write-Host ("-{0}" -f $parm.name) -NoNewline -ForegroundColor Gray # +1x | |
Write-Host (" <{0}>" -f $parm.type) -NoNewline -ForegroundColor Yellow # +3x | |
Write-Host "] " -NoNewline # +2 | |
} | |
$curLength += ($parm.name.Length + $parm.type.Length + 7) | |
if($curLength -gt $width) | |
{ | |
$curLength = 0 | |
Write-Host | |
} | |
} | |
Write-Host | |
} | |
function Get-ColoredSyntax2 ($command) | |
{ | |
Write-Host ("{0} " -f (get-help $command).name) -NoNewline -ForegroundColor White | |
$syn = ((get-help $command).syntax.syntaxitem.parameter) | select name, @{Name='type'; Expression = {$_.type.name}}, required | |
$width = 170 | |
if ($host.UI.RawUI.WindowSize.Width -notin ("", $null)) { | |
$width = $host.UI.RawUI.WindowSize.Width | |
} | |
$curLength = 0 | |
foreach($parm in $syn) { | |
if ($parm.required -eq $true) { | |
Write-Host ("{0} <{1}>" -f $parm.name, $parm.type) -NoNewline -ForegroundColor Green # +3x | |
} | |
else { | |
Write-Host ("{0} <{1}>" -f $parm.name, $parm.type) -NoNewline -ForegroundColor Gray # +3x | |
} | |
Write-Host " | " -NoNewline | |
$curLength += ($parm.name.Length + $parm.type.Length + 7) | |
if($curLength -gt $width) | |
{ | |
$curLength = 0 | |
Write-Host | |
} | |
} | |
Write-Host | |
} | |
cls | |
Get-ColoredSyntax irm | |
"" | |
Get-ColoredSyntax2 irm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment