Last active
September 16, 2018 06:01
-
-
Save klumsy/d430c9b871946eca18eed086563d8dbb to your computer and use it in GitHub Desktop.
Use Numbers on MacOS to display Powershell Data similar to Out-GridView
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 Out-Numbers { | |
<# | |
.SYNOPSIS | |
Converts PowerShell Objects in CSV and opens in Numbers on macOS | |
.DESCRIPTION | |
Converts PowerShell Objects in CSV and opens in Numbers on macOS | |
TODO, maybe allow passing through a filename, an only using temp if not. | |
then allow certian parameters for export-csv like type, or no clobber or append.. | |
.PARAMETER InputObject | |
Object to output | |
.PARAMETER Title | |
Title for the grid and dashboard. | |
.EXAMPLE | |
Get-Command | Select commandtype , name , version | Out-Numbers | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
$InputObject | |
) | |
Begin { | |
$Script:Items = new-object -typename System.Collections.ArrayList | |
} | |
Process { | |
[void] $Script:Items.add($InputObject) | |
} | |
End { | |
$tempfilename = "/tmp/outnumber$([string](new-guid) -replace '-','').csv" #this path is deleted on reboot | |
$items | Export-Csv -Path $tempfilename | |
open /Applications/Numbers.app/ $tempfilename | |
} | |
} |
For large inputs you'll see perf issues as the +=
is rebuilding the array each time. You can use System.Collections.Generic.List<T>
and $Items.Add($elem)
instead.
Also slight nitpick, it's macOS not MACOS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Use:
get-process | group processname | Sort-Object count -Descending | select -first 20 | select name, count | Out-numbers