How To Use Out-Gridview As A GUI In PowerShell

The Out-Gridview cmdlet sends output from a command, to grid view window that acts as an interactive GUI. The Gridview allows you to sort and filter your data. More importantly for our purposes, the cmdlet includes the -PassThru parameter. This allows us to select items from the table that we would like to pass down the pipeline to be used as input for other commands. Functionally, a built in GUI to allow data selection.

In this Snip we will demonstrate this functionality passing object to Start-Service and Stop-Service

Prerequisites include: - Windows PowerShell 5.1 - Visual Studio Code with PowerShell extension (optional)

Today we're going to take a look at the out. Gridview commandlet out gridview sends the output of a command to a grid view window. That acts and interactive graphical user interface. This grid view will allow you to sort or filter your data but more importantly, if you use the pass through parameter. It will let you select data to send through the pipeline to pass that output to other commands. So today to demonstrate the functionality of out gridview. We're going to use start service and stop service to select some services and see the changes take place. So to get started the first thing we're going to want to do is I arbitrarily picked some Xbox services were going to take a look at a subset of services so in this case, we're going to get service and take a look. As you can see we have 5 services that are all stopped relating to the Xbox. We're going to run get service type that output to out gridview with the dash pass through parameter. The dash pass through parameter is what is going to let us send that output onto another command and in this case we're going to use start service. We can see that in powershell, the grid view. Display screen will pop up what we have here is the output from get service and we can select a couple of these services to actually pass through to start so for our example. We're just going to arbitrarily select 3 of these services holding the control. Key you can highlight additional lines and then select OK to pass this through to start service. And then now again we can take a look at the the output from get service and will see that we have successfully started 3 of the services in reverse, we can do the same thing we can pass this same output back to stop service. We'll take a look so we've got 3 running services. Let's pick, 2 of these to stop again using the control key will allow us to highlight multiple lines. We select OK back to our command prompt and we just want to take a look at what services are running. We can see we successfully stop to those services, we selected those objects to pass back to stop service parameter will do it, one more time we're going to stop this last service. We want to call get service pass it through the out gridview with the pass through parameter and then. Passed out through stop service. Get a pop up window again. The one service remaining running that we want to stop will select it. Select OK and then here will will finish up with a. Taking a look at what's running. We're back to the initial state you can use this with any object you want to pass through. It's really just that simple, The pass through parameter incredibly helpful.