---
title: "PowerShell Write-Output: Your Friendly Output Companion"
description: "Learn all of the ins and outs of the PowerShell Write-Output cmdlet and take control of script and object output in this ATA Learning tutorial!"
canonical: "https://adamtheautomator.com/powershell-write-output/"
---

# PowerShell Write-Output: Your Friendly Output Companion

> Learn all of the ins and outs of the PowerShell Write-Output cmdlet and take control of script and object output in this ATA Learning tutorial!

Source: https://adamtheautomator.com/powershell-write-output/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Write-Output: Your Friendly Output Companion](https://adamtheautomator.com/wp-content/uploads/2023/02/powershell-write-output.jpg)

# PowerShell Write-Output: Your Friendly Output Companion

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)6 February 20237 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)[PowerShell Language](/tag/powershell-language/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Outputting Objects to the Console](#outputting-objects-to-the-console)
*   [Passing Objects to Another Command](#passing-objects-to-another-command)
*   [Outputting Objects with a Custom Format](#outputting-objects-with-a-custom-format)
*   [Passing a Collection Object as a Single Entity](#passing-a-collection-object-as-a-single-entity)
*   [Creating a Menu System and Input Prompts](#creating-a-menu-system-and-input-prompts)
*   [Displaying a Splash Screen or Welcome Message](#displaying-a-splash-screen-or-welcome-message)
*   [Displaying a Progress Bar](#displaying-a-progress-bar)
*   [Conclusion](#conclusion)

Say goodbye to dull, predictable script output! With the PowerShell `Write-Output` cmdlet, you can add a touch of creativity and personality to your PowerShell scripts.

The `Write-Output` cmdlet is a powerful tool and a perfect companion for all your automation and system management needs. And in this tutorial, you will learn to maximize the `Write-Output` cmdlet’s potential.

Ready? Read on and discover the magic of the `Write-Output` cmdlet!

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, be sure you have a computer with PowerShell installed (preferably the latest version). This tutorial uses Windows 10 with PowerShell 7 installed.

Related:[PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

## Outputting Objects to the Console

The PowerShell `Write-Output` cmdlet writes objects to the output stream and displays the output of a command or message in the console. But you will be surprised how this tool makes the output more meaningful and valuable.

Related:[Back to Basics: Understanding PowerShell Objects](https://adamtheautomator.com/powershell-objects/)

Instead of displaying the output in the console, use the `Write-Output` cmdlet to customize the output. The `Write-Output` cmdlet can output any object or data type, such as strings, integers, arrays, and even complex objects.

Run the below command to output a **Hello, World!** message to the console.

```powershell
Write-Output "Hello, World!”
```

Below, you can see the most basic function of the `Write-Output` cmdlet. But read on to learn more intermediate to advanced usage of this cmdlet.<>

![Outputting objects to the console](https://adamtheautomator.com/wp-content/uploads/2023/02/image-29.png)

Outputting objects to the console

## Passing Objects to Another Command

In addition to displaying the output in the console, you can use the `Write-Output` command to send the object to another command for further processing. How? By using the pipeline operator (`|`). [Pipelining](https://adamtheautomator.com/ppowershell-pipeline/) makes `Write-Output` a handy and versatile command for automation and system management tasks.

Related:[Getting to Know the PowerShell Pipeline and Creating Functions](https://adamtheautomator.com/ppowershell-pipeline/)

Suppose you wish to see which process consumes most of your resources, like the CPU.

Run the commands below to perform the following:

*   Retrieve a list of all processes (`Get-Process`) running on your system.
*   Output the list to the pipeline, which is then passed to the `Sort-Object` command. The pipeline operator allows you to chain multiple commands together and process the output of one command as the input for another.
*   Sort the list of processes (`Sort-Object`) by their `CPU` usage in `-Descending` order.

```powershell
$processes = Get-Process
Write-Output $processes | Sort-Object CPU -Descending
```

> _Note that you can put any of the commands in this tutorial into a PowerShell script and run it._

Related:[How to Run a PowerShell Script From the Command Line and More](https://adamtheautomator.com/run-powershell-script/)

The sorted list is displayed in the console, as shown below.

![powershell write-output - Passing objects to another command](https://adamtheautomator.com/wp-content/uploads/2023/02/image-30.png)

Passing objects to another command

## Outputting Objects with a Custom Format

You have seen the Write-Output cmdlet’s basic output format, which works fine. But if you like, you can also output objects with a custom format to add a personal touch. A custom format can be useful when you wish to display specific object properties or customize the output’s appearance.

To output an object with a custom format, the `Format-Custom` together with the `Write-Output` cmdlet will do the trick, as follows:

to create the custom output format, and then pipe the output of the Format-Custom cmdlet to Write-Output.<>

Run the below command, which does not produce output, but creates an object (a hashtable) that contains three properties with the corresponding values to output.

Related:[A Beginner Guide to Using PowerShell Hashtable](https://adamtheautomator.com/powershell-hashtable/)

```powershell
$object = [pscustomobject]@{
Property1 = "Value1"
Property2 = "Value2"
Property3 = "Value3"
}
```

Now, run the below command to perform the following:

*   Create a custom format (`Format-Table`) for the output (`Write-Output`) of your hashtable (`$object`). The `Property1`, `Property2`, and `Property3` properties are set as columns.
*   Adjust the column widths (`-AutoSize`) to fit the content.

```powershell
$object | Format-Table -Property Property1, Property2, Property3 -AutoSize | Write-Output
```

![](https://ata-proxy-cors-headers.adamtheautomator.workers.dev/?https://adamtheautomator.com/wp-content/uploads/2023/04/image-55-1024x109.png)

Creating a custom format for an object output

Alternatively, you can use the `Format-List` cmdlet with `Write-Output` to output the object as a list of property-value pairs.

```powershell
$object | Format-List -Property Property1, Property2, Property3 | Write-Output
```

![Outputting the object as a list of property-value pairs](https://adamtheautomator.com/wp-content/uploads/2023/02/image-32.png)

Outputting the object as a list of property-value pairs

## Passing a Collection Object as a Single Entity

By default, `Write-Output` sends each collection element through the pipeline separately, a process called enumeration. But you can prevent this behavior by appending the `-NoEnumerate` parameter, passing the entire collection object as a single entity.

To see how the `-NoEnumerate` parameter works, follow these steps:

Run the commands below to perform the following:

*   Declare an array of `$numbers` from one to three (`1,2,3`).

Related:[Build Better Scripts with PowerShell ArrayLists and Arrays](https://adamtheautomator.com/powershell-array/)

*   Count the number of objects (`Measure-Object`) passed through the pipeline.
*   Output the object measurement (`Write-Output $numbers`).

Without the `NoEnumerate` parameter, `Measure-Object` returns a count of three (**3**), as each element of the `$numbers` array was enumerated and passed individually through the pipeline.

```powershell
# Declares an Array
$numbers = 1,2,3
# Outputs the object count passed through the pipeline
Write-Output $numbers | Measure-Object
```

![Outputting an array object measurement](https://adamtheautomator.com/wp-content/uploads/2023/02/image-33.png)

Outputting an array object measurement

Now, run the following commands to output the count of the objects passed through the pipeline.

But since you appended the `-NoEnumerate` parameter, the `Measure-Object` cmdlet treats the object as a single entity, returning a count of one (**1**).

```powershell
# Declares an Array
$numbers = 1,2,3
# Outputs the object count as a single entity passed through the pipeline
Write-Output -NoEnumerate $numbers | Measure-Object
```

![Outputting object count as a single entity](https://adamtheautomator.com/wp-content/uploads/2023/02/image-34.png)

Outputting object count as a single entity

> _Enclosing the `Write-Output` command in parentheses (i.e., `(Write-Output 1,2,3)`) will force enumeration to happen regardless of the `-NoEnumerate` parameter._

## Creating a Menu System and Input Prompts

Another excellent use of the `Write-Output` cmdlet is creating a menu system with a PowerShell script that prompts the user for input.

Create a _.ps1_ file with your preferred text/code editor, populate the code below, and save the file. You can name the file as you like, but this tutorial’s choice is _myoutput.ps1_.

Related:[How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/powershell-text-editor/)

The code below uses a loop to continually prompt the user to select an option from a list of options until the user selects the `Exit` option.

Related:[The PowerShell While Loop : A Back to Basic Guide](https://adamtheautomator.com/powershell-while-loop/)

```powershell
# Initialize the $exit variable to $false
$exit = $false

# Start a loop that will run until the user selects the "Exit" option
while (!$exit) {

  # Display a list of options to the user
  Write-Output "Please select from the following options:"
  Write-Output "1. Option 1"
  Write-Output "2. Option 2"
  Write-Output "3. Option 3"
  Write-Output "4. Exit"

  # Prompt the user for a selection
  $selection = Read-Host

  # Use a switch statement to execute different codes based on the user's selection
  switch ($selection) {
    1 {
      # If the user selects option 1, display a message and do something for option 1
      Write-Output "You selected Option 1."
      # Do something for option 1
    }
    2 {
      # If the user selects option 2, display a message and do something for option 2
      Write-Output "You selected Option 2."
      # Do something for option 2
    }
    3 {
      # If the user selects option 3, display a message and do something for option 3
      Write-Output "You selected Option 3."
      # Do something for option 3
    }
    4 {
      # If the user selects option 4, set $exit to $true to exit the loop
      $exit = $true
    }
  }
}
```

Now, run the script (_`myoutput.ps1`_) from the working directory.

```powershell
./myoutput.ps1
```

As shown below, the message associated with your selection is displayed when you choose options **1**, **2**, or **3**. But when you select option **4**, the script terminates.

![Creating a menu system and input prompts](https://adamtheautomator.com/wp-content/uploads/2023/02/image-35.png)

Creating a menu system and input prompts

## Displaying a Splash Screen or Welcome Message

Besides listing options the users can choose from, with `Write-Output`, you can also display a splash screen or a welcome message. Fancy splash screens make a good impression (professional and polished) on your script.

Replace the code in your _myoutput.ps1_ file with the one below, which outputs a splash screen (a banner of a welcome message) when you run your script.

> _You can customize the splash screen by modifying the text and formatting of the banner. You can add additional elements, such as a logo or text, to the splash screen as desired._

```powershell
# Clear the screen
Clear-Host

# Display the splash screen using Write-Output
Write-Output "##############################################"
Write-Output "#                                            #"
Write-Output "#   Welcome to the SuperScript 3000!         #"
Write-Output "#                                            #"
Write-Output "##############################################"
```

Now, run the script and see how your splash screen looks.

```powershell
./myoutput.ps1
```

![Displaying a splash screen or welcome message](https://adamtheautomator.com/wp-content/uploads/2023/02/image.gif)

Displaying a splash screen or welcome message

## Displaying a Progress Bar

When running scripts, a progress indicator eliminates a user’s anxiety about whether the script is running or not. Progress bars can be useful for indicating the progress of a long-running script or operation to the user. Luckily, with the `Write-Output` cmdlet, you can craft a progress bar to your liking.

Open your _myoutput.ps1_ file, and add the code below to the bottom of the existing one in the script file.

The code below uses a `while` loop to iterate through several steps. In this example, 100 steps. Each iteration of the loop calculates the percentage of steps that have been completed and displays a progress bar using `Write-Output`.

The progress bar is created using a combination of the following operators:

*   `*` – Repeats a string a specified number of times
*   `$()` – Allows the output of an expression to be included in a string.

The script then pauses (`Start-Sleep`) for `1` second to simulate progress before moving on to the next step.

```powershell
# Set the total number of steps for the progress bar
$steps = 100

# Initialize the counter for the current step
$currentStep = 0

# Start a loop that will run for the number of steps
while ($currentStep -lt $steps) {
  # Increment the current step counter
  $currentStep++

  # Calculate the percentage of steps completed
  $percentComplete = [int] ($currentStep / $steps * 100)

  # Display a progress bar using Write-Output
  Write-Output "Progress: [$("=" * $percentComplete)$(" " * ($steps-$percentComplete))] $percentComplete% complete"

  # Pause for 1 second to simulate the progress
  Start-Sleep -Seconds 1
}
```

Now, run the script and see how the progress bar works.

```powershell
./myoutput.ps1
```

Below, you can see the splash screen together with the progress bar.

![Displaying a progress bar](https://adamtheautomator.com/wp-content/uploads/2023/02/image-1.gif)

Displaying a progress bar

## Conclusion

In this tutorial, you have seen how `Write-Output` can easily output objects, [data types](https://www.techtarget.com/searchapparchitecture/definition/data-type), and custom formats. Moreover, you touched on using the pipeline operator to send output to other commands for further processing.

Whether you are writing a simple message output or complex automation tasks, `Write-Output` is an indispensable tool for creating more informative and professional PowerShell scripts.

With this newfound knowledge, why not write your outputs to different file types, like _.txt_ and _.xml_ files? Regardless of the intent, output copies come in handy in troubleshooting issues with your system or applications. The `Write-Output` and the `Out-File` cmdlet grant you the power you never knew you needed.

Related:[Using PowerShell Out-File Cmdlet to Redirect Output to a File](https://adamtheautomator.com/out-file/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-write-output%2F&text=PowerShell%20Write-Output%3A%20Your%20Friendly%20Output%20Companion)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-write-output%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-write-output%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/08/powershell-approved-verbs.jpg)

### [Your Getting Started Guide to PowerShell Approved Verbs](/powershell-approved-verbs/)

Discover how to get started with PowerShell Approved Verbs to make sure your scripts and code is top-notch in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2023/07/powershell-sort-object.jpg)

### [Learning PowerShell Sort-Object with Examples](/powershell-sort-object/)

Learn all of the ins-and-outs of the PowerShell Sort-Object cmdlet in this example driven tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2023/03/powershell-change-directory.jpg)

### [PowerShell Change Directory: Navigating Your File System](/powershell-change-directory/)

Learn how to use the PowerShell change directory command to navigate your file system with ease. Master the basics of PowerShell file navigation today.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
