Created
November 3, 2023 15:55
-
-
Save trackd/297487878b02d2192244c1c4f91c2690 to your computer and use it in GitHub Desktop.
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 table { | |
<# | |
format-table sugar that knows not to format if you're assigning to a variable. | |
it will automatically switch to Select-Object when assigned. | |
only implemented Property param atm, just testing it out for fun. | |
Set-Alias -Name ft -Value table -Force | |
to override default ft alias you need -Force. | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[object] $InputObject, | |
[Parameter(Position = 0)] | |
[object[]] $Property | |
) | |
begin { | |
$assigned = ([System.Management.Automation.Language.Parser]::ParseInput($MyInvocation.Line, [ref]$null, [ref]$null)).EndBlock.Statements[0].operator | |
if ($assigned) { | |
$step = { Select-Object @PSBoundParameters }.GetSteppablePipeline() | |
} | |
else { | |
$step = { Format-Table @PSBoundParameters }.GetSteppablePipeline() | |
} | |
$step.Begin($PSCmdlet) | |
} | |
process { | |
$step.Process($InputObject) | |
} | |
end { | |
$step.End() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment