Skip to content

Instantly share code, notes, and snippets.

@klumsy
Last active September 16, 2018 06:01
Show Gist options
  • Save klumsy/d430c9b871946eca18eed086563d8dbb to your computer and use it in GitHub Desktop.
Save klumsy/d430c9b871946eca18eed086563d8dbb to your computer and use it in GitHub Desktop.
Use Numbers on MacOS to display Powershell Data similar to Out-GridView
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
}
}
@klumsy
Copy link
Author

klumsy commented Sep 16, 2018

Example Use:
get-process | group processname | Sort-Object count -Descending | select -first 20 | select name, count | Out-numbers

@klumsy
Copy link
Author

klumsy commented Sep 16, 2018

Example with Screenshot
Get-Command | Select commandtype , name , version | Out-Numbers

image

@jcotton42
Copy link

jcotton42 commented Sep 16, 2018

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