DataGrid
The AnyBox also has the ability to display data to a user in a DataGrid. All you need to do is pass an array to the -GridData
parameter.
Show-AnyBox -Title 'Powershell Processes' -Buttons 'OK' -GridData @(
Get-Process -Name 'powershell' |
select Id, Name, TotalProcessorTime, Path
)
You may notice a few useful additions that are included automatically. Above the data grid is a message indicating how many items are in the grid, and a text box that allows users to filter the grid items. This can be disabled using the -NoGridSearch
parameter.
All default grid-related buttons, including 'Save' and 'Explore', have been removed, but they can be easily replicated with the new -Template
option of New-AnyBoxButton
:
$sav_btn = New-AnyBoxButton -Template SaveGrid
$exp_btn = New-AnyBoxButton -Template ExploreGrid
Show-AnyBox -Title 'Powershell Processes' -Buttons @($exp_btn, $sav_btn) -GridData @(
Get-Process -Name 'powershell' | select Id, Name, TotalProcessorTime, Path
)
The parameter -SelectionMode
is available for the data grid and controls how grid cells are selected. Selected grid items are made available in the AnyBox output via the 'grid_select' key.
Show-AnyBox -Title 'Select processes to kill' `
-NoGridSearch -SelectionMode 'MultiRow' -Buttons 'Cancel', 'Kill' `
-GridData @(Get-Process -Name '*note*' | select Id, Name, TotalProcessorTime, Path)
Name Value
---- -----
Cancel False
grid_select {@{Id=2680; Name=powershell;...
Kill True
Sometimes, you may find that you only have one object with many properties to display. By default, the AnyBox will display this object with one row and many columns. It may be more appropriate to melt the object to a long format. The AnyBox function includes a parameter, -GridAsList
, that makes this simple.
Show-AnyBox -Title 'Wide (as-is)' -Buttons 'OK' -NoGridSearch -GridData $car
Show-AnyBox -Buttons 'OK' -NoGridSearch -GridData $car -GridAsList