Out GridView - PowerShell
Overview
The Out-GridView
command in PowerShell creates an interactive graphical window that allows you to view and interact with tabular data. It presents the data in a grid format, enabling you to sort, filter, and perform various operations on the displayed records.
Syntax
Out-GridView [[-InputObject] <object>] [-Title <string>] [-PassThru] [-NoWrap] [-Width <int>] [-AutoSizeColumns] [-Force] [-Wrap] [-Height <int>] [-Background <color>] [-Foreground <color>] [-Font <font>] [-InputObjectProcessedCount <int>] [-MaximumWindowHeight <int>] [-MaximumWindowWidth <int>] [-MinimumWindowHeight <int>] [-MinimumWindowWidth <int>] [-AllowResize] [-AllowColumnHeaderReorder] [-AllowColumnReorder] [-AllowSort] [-AllowVirtualization] [-AutoFit] [-AutoSize] [-CellSpan <int>] [-ColumnHeadersHeight <int>] [-ColumnIndent] [-ColumnSpacing <int>] [-DetailPaneHeight <int>] [-DisableDpiAwareness] [-DisableVirtualization] [-DisplayCursorPosition] [-EnableDpiAwareness] [-ForbiddenKeyDown] [-ForbiddenKeyUp] [-ForbiddenKeyDownChar] [-ForbiddenKeyUpChar] [-HeaderCellOpacity <byte>] [-HeaderCellForeground <color>] [-HeaderCellHeight <int>] [-HeaderCellHorizontalAlignment <string>] [-HeaderCell-LineBreakText <string>] [-HeaderCellOverflow <string>] [-HeaderCellPadding <int>] [-HeaderCellTextAlignment <string>] [-HeaderCellVerticalAlignment <string>] [-IdleTimeout <int>] [-Indent <int>] [-MultiSelect] [-NoClickSelection] [-NoScroll] [-Pagination <int>] [-ReadOnly] [-UseSystemHotkeys] [-SelectionMode <string>] [-ShowColumnHeaders <boolean>] [-ShowDetailsPane <boolean>] [-ShowGridLines <boolean>] [-ShowItemCount <boolean>] [-ShowRowHeader <boolean>] [-SortControlPlacement <string>]
Options/Flags
- -Title
: Sets the title of the grid window. - -PassThru: Passes the input object to the output.
- -NoWrap: Prevents text wrapping in cells.
- -Width
: Specifies the width of the window in pixels. - -AutoSizeColumns: Automatically adjusts column widths to best fit the content.
- -Force: Overrides any existing window and displays the grid.
- -Wrap: Allows text wrapping in cells.
- -Height
: Specifies the height of the window in pixels. - -Background
: Sets the background color of the grid. - -Foreground
: Sets the foreground color of the text and controls. - -Font : Specifies the font to use in the grid.
- -InputObjectProcessedCount
: Limits the number of input objects to process before the grid is displayed. - -MaximumWindowHeight
: Specifies the maximum height of the grid window. - -MaximumWindowWidth
: Specifies the maximum width of the grid window. - -MinimumWindowHeight
: Specifies the minimum height of the grid window. - -MinimumWindowWidth
: Specifies the minimum width of the grid window. - -AllowResize: Enables user resizing of the grid window.
- -AllowColumnHeaderReorder: Allows users to reorder column headers.
- -AllowColumnReorder: Allows users to reorder columns.
- -AllowSort: Enables sorting of data in the grid.
- -AllowVirtualization: Optimizes performance for large datasets by only loading visible rows.
- -AutoFit: Automatically sizes the grid to fit the available space.
- -AutoSize: Automatically sizes the grid based on its content.
- -CellSpan
: Sets the number of cells to span for a cell. - -ColumnHeadersHeight
: Specifies the height of the column header area. - -ColumnIndent: Indents the column header text.
- -ColumnSpacing
: Sets the space between columns. - -DetailPaneHeight
: Specifies the height of the detail pane area. - -DisableDpiAwareness: Disables DPI awareness for the grid window.
- -DisableVirtualization: Disables virtualization for the grid.
- -DisplayCursorPosition: Shows the current cursor position in the grid.
- -EnableDpiAwareness: Enables DPI awareness for the grid window.
- -ForbiddenKeydown: Specifies a key or key combination to disable from being pressed.
- -ForbiddenKeyup: Specifies a key or key combination to disable from being released.
- -ForbiddenKeyDownChar: Specifies a character to disable from being entered when a key is pressed.
- -ForbiddenKeyUpChar: Specifies a character to disable from being entered when a key is released.
- -HeaderCellOpacity
: Sets the opacity of the header cell background. - -HeaderCellForeground
: Sets the foreground color of the header cell text and controls. - -HeaderCellHeight
: Specifies the height of the header cells. - -HeaderCellHorizontalAlignment
: Sets the horizontal alignment of the header cell text. - -HeaderCell-LineBreakText
: Sets the text to use for line breaks in the header cell. - -HeaderCellOverflow
: Sets the behavior when the header cell text overflows. - -HeaderCellPadding
: Sets the padding around the header cell text. - -HeaderCellTextAlignment
: Sets the text alignment of the header cell text. - -HeaderCellVerticalAlignment
: Sets the vertical alignment of the header cell text. - -IdleTimeout
: Specifies the time in milliseconds before the grid becomes idle and performs cleanup tasks. - -Indent
: Indents the grid content by the specified number of pixels. - -MultiSelect: Enables the selection of multiple rows.
- -NoClickSelection: Disables row selection by clicking.
- -NoScroll: Disables scrolling in the grid.
- -Pagination
: Sets the number of rows to display per page. - -ReadOnly: Prevents users from modifying the grid data.
- -UseSystemHotkeys: Uses system hotkeys for grid operations.
- -SelectionMode
: Sets the selection mode for the grid. - -ShowColumnHeaders
: Shows the column headers. - -ShowDetailsPane
: Shows the details pane area. - -ShowGridLines
: Shows grid lines between rows and columns. - -ShowItemCount
: Shows the number of rows in the grid. - -ShowRowHeader
: Shows the row header area. - -SortControlPlacement
: Sets the placement of the sort control.
Examples
Simple usage:
Get-Process | Out-GridView
Displaying a specific number of rows:
Get-Process | Out-GridView -Pagination 10
Disabling scrolling and showing row count:
Get-Process | Out-GridView -NoScroll -ShowItemCount
Selecting multiple rows:
Get-Process | Out-GridView -MultiSelect
Common Issues
- Slow performance when dealing with large datasets: Consider enabling virtualization using the
-AllowVirtualization
parameter. - Rows disappearing from the grid: Ensure that the input data is not changing while the grid is open.
- Grid not displaying correctly: Check the size and positioning of the grid window, as well as the DPI settings of your system.
Integration
Out-GridView
can be integrated with other PowerShell commands to perform advanced data manipulation and visualization tasks. For instance:
- Export the grid data to a CSV file:
Get-Process | Out-GridView | Export-Csv -Path .\processes.csv
- Create a graphical report based on the grid data:
Get-Process | Out-GridView | Select-Object ProcessName | ConvertTo-Html -Title "Process Report" -Body "<h3>Current Processes</h3>" | Out-File .\report.html
Related Commands
- Get-Content: Reads data from files or streams.
- Write-Host: Writes text to the console.
- ConvertTo-Html: Converts data into HTML format.