Chapter 16. Input and output

 

So far in this book, we’ve primarily been relying on PowerShell’s native ability to output tables and lists. As you start to combine commands into more complex scripts, you’ll probably want to gain more precise control over what’s displayed. You may also have a need to prompt a user for input. In this chapter, you’ll learn how to collect that input, and how to display whatever output you might desire.

16.1. Prompting for, and displaying, information

How PowerShell displays and prompts for information depends on how PowerShell is being run. You see, PowerShell is built as a kind of under-the-hood engine.

What you interact with is called a host application. The command-line console that you see when running PowerShell.exe is often called the console host. The graphical PowerShell ISE is usually called the ISE host or the graphical host. Other non-Microsoft applications can host the shell’s engine, as well. You interact with the hosting application, and it passes your commands through to the engine. Whatever results the engine produces are displayed by the hosting application.

16.2. Read-Host

16.3. Write-Host

16.4. Write-Output

16.5. Other ways to write

16.6. Lab

16.7. Ideas for on your own

sitemap