PowerShell 2.0: One Cmdlet at a Time 4 Out-GridView
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Out-GridView cmdlet.
What can I do with it?
View the output from a command in an interactive grid window.
Any special requirements?
Whilst PowerShell 2.0 itself requires .NET Framework 2.0 with Service Pack 1, this particular cmdlet requires .NET Framework 3.5 Service Pack 1.
Examples:
Create an interactive grid view of the list of services running on the machine.
Get-Service | Out-GridView
The resulting output with a filter of Windows and sorted by Status gives you an idea for what you can use this for:
Create an interactive grid view of the System log with the latest 5 entries, selecting only the Source and Message properties and displaying the Output with a custom title.
Get-Eventlog -Logname System -Newest 5 | Select-Object Source,Message | Out-GridView -Title ‘System Log’
Tip:
I don’t recommend using aliases within a script, but this is the kind of cmdlet you are most likely to use when working at the command line so the alias for Out-Gridview, ogv , could come in very handy.
How could I have done this in PowerShell 1.0?
The closest you could probably get would be Export-CSV to give you the data in a CSV file, which could then be manipulated in a similar fashion to Out-GridView using Excel.
Get-Service | Export-Csv C:\Scripts\Services.csv -NoTypeInformation