In my previous post, I showed how you can build a simple menu driven PowerShell GUI; check it out here. To further improve upon that simple GUI, we will go over how to use Out-GridView. Out-GridView is a built-in powershell cmdlet that sends the output from a given command to an interactive window. This post will discuss several different use cases and how you can incorporate them into your code.
Why use Out-GridView?
- Simplicity
- Built-in to PowerShell
- Customizable
- Powerful
Parameters
Let’s first start off by going over the parameters that will be covered in this post and the values that can be used.
- OutputMode
- Single: This limits your selection to one object; use this if the next command can only take one value as input.
- Multiple: This allows you to select multiple objects at a time; use this if the next command can handle multiple values as input.
- None: Nothing will be able to be selected, use this if you just want a report. This is the default value.
- Title
- This is where you put your descriptive name for the Out-GridView window. Any additional instructions should be placed here as well.
Code Examples
There are several ways of getting data into Out-GridView, as well as multiple ways of outputting data from Out-GridView. We will cover the methods that I utilize most frequently.
Method 1: Input directly from command, display results only
The most basic function of Out-GridView is to just simply display data to the user. In the below example, we do a Get-Service command to get all the services on a given system, then we pipe those results to Out-GridView to be viewed. We have set a title for the Out-GridView window and set the outputmode to None which means that there is no “OK” or “Cancel” button and no data will be passed along to the next command.
Get-Service | Out-GridView -Title "List of all the services on this system" -OutputMode None

Method 2: Input from variable, single output
A slightly more advanced option will use a variable to hold all of the output from the Get-Service command and then we will pipe that variable to Out-GridView. This gives us more flexibility and the ability to reuse the variable in other parts of the script if needed. We set the title for the Out-GridView window again, but this time we set the outputmode to Single which means that there will be an “OK” and “Cancel” button while only allowing the user to select one value. That one value selected will be stored in the variable specified ($single_output). In this example we utilize the Stop-Service command to stop the selected service.
$services = Get-Service ### Getting all services on the system and sending them to the services variable
$single_output = $services | Out-GridView -Title "Select the service that you want to stop" -OutputMode Single ### Sending the services variable to Out-GridView, the single service selected will be sent to single_output variable
Write-Host "Stopping service" $single_output.Name -BackgroundColor Cyan -ForegroundColor Black
Stop-Service $single_output.Name ### Finally the service selected will be stopped
Selecting a single service and then clicking the “OK” button will cause the selected service to be stopped.

Method 3: Input from custom array, multiple output
An even slightly more advanced option will use a custom array to hold all of the data from the services variable. The services variable will be populated from the Get-Service command and then piped to Where-Object which will only include services with a “Running” status. The array will be populated with all of the Running services from the Foreach loop. The custom array will then be piped to Out-GridView. The custom array is not entirely necessary for this simple example of stopping services but it could be useful with more complex scripts where you need to combine data from multiple sources. We set the title for the Out-GridView window again, but this time we set the outputmode to Multiple which means that there will be an “OK” and “Cancel” button while allowing the user to select multiple values. Multiple values can be selected by holding CTRL while clicking on the desired values. All the values can be selected by hitting CTRL + A. The values selected will be stored in the variable specified ($multiple_output). In this example, we utilize the Stop-Service command inside of a Foreach loop in order to stop the multiple selected services.
$custom_array = @() ### Creating an empty array to populate data in
$services = Get-Service | Select Name, Status, DisplayName, StartType | Where-Object {$_.Status -eq "Running"} ### Getting Running services on the system and sending them to the services variable
### Looping through all of the running services and adding them to the custom array
Foreach ($service in $services){
### Setting up custom array utilizing a PSObject
$custom_array += New-Object PSObject -Property @{
Service_Name = $service.Name
Service_Status = $service.Status
Service_DisplayName = $service.DisplayName
Service_StartType = $service.StartType
}
}
$multiple_output = $custom_array | Out-GridView -Title "This is using a custom array with multiple output values" -OutputMode Multiple
### Looping through all of the selected services and stopping the service
Foreach ($output in $multiple_output){
Write-Host "Stopping service" $output.Service_Name -BackgroundColor Cyan -ForegroundColor Black
Stop-Service $output.Service_Name ### Finally the service selected will be stopped
}
Selecting multiple services (Hold CTRL while clicking desired service) and then clicking the “OK” button will cause the selected services to be stopped. (CTRL + A to select all)

That’s it for now, thanks for reading!
Check out my other blog posts:
Media Sync: Organize Your Photos and Videos with PowerShell
Do you have photos and videos that you have taken over the years that are scattered all over the place? Do you want to have all your photos and videos organized? Do you want all your photos and videos to have a standardized naming scheme? If you answered YES to these questions, then this is…
NetNeighbor Watch: The PowerShell Alternative To Arpwatch
In this post, we are going to setup NetNeighbor Watch on a Raspberry Pi. NetNeighbor Watch can keep an eye on your network and send you an email when a new host is discovered. NetNeighbor Watch is done completely in PowerShell. The results are very similar to those of arpwatch. NetNeighbor Watch is for anyone…
Generate a Citrix Desktop Report Based on Active Directory Users
In this post, we are going to merge data from two different sources to generate a report that can provide insight into your Citrix environment. I will show you how to combine Active Directory data for the users in your domain with Citrix data. This report will provide you with the following knowledge: Users that…
Creating a PowerShell Module to Improve Your Code
Do you have PowerShell code that you reuse in your scripts over and over? Do you have server names hard coded in variables? Are you using a text file or CSV file to import server names? Do you find yourself only utilizing one server out of a cluster of servers to make your PowerShell commands?…
Generate a DHCP Report Via PowerShell
Today we are going to look at how to generate a DHCP scope statistics HTML report by using PowerShell. This report will give you one location to see all of your DHCP scope statistics across all of your Windows DHCP servers. It will dynamically pull the DHCP servers and associated DHCP scopes within your Active…
Increase VMware VM Disk Size with PowerShell
In this post, I will cover how to use PowerShell to increase the disk size of a Windows 10 VM running in a VMware vCenter environment. Automating simple but time consuming tasks like this can save precious time for your support staff or yourself. There are two parts to accomplishing this task; first we need…
Manage Citrix Tags with PowerShell
In this post, we are going to cover how to manage Citrix tags with PowerShell. Citrix Studio is a great tool, but it can be very time consuming especially if you have to do bulk tag actions. Citrix tags can be used in several methods, but this post is focused on desktop tagging. This post…
Create a Text Box to Accept User Input for PowerShell GUI
Do you have a PowerShell GUI that needs to accept text input? Maybe you want to be able to copy and paste a list of computers, ip addresses, user names or some other data. I will show you how to add a text box into your PowerShell GUI to handle that input. If you haven’t…
How to Create a Simple PowerShell GUI
Have you ever wanted to create a menu driven PowerShell GUI to conduct a series of automated tasks? You are in luck, because that is exactly what we are going to cover in this post. This very simple PowerShell GUI will help you easily distribute your code to other team members or maybe you just…
2 thoughts on “Utilizing PowerShell Out-GridView as a GUI Alternative”