Chapter 9. Formatting

 

This chapter covers

  • PowerShell’s formatting system
  • PowerShell’s Format cmdlets
  • Creating custom formats
  • Formatting tips

PowerShell, as you’ve learned in the preceding chapters, works primarily with objects. Objects are just an in-memory data structure. But the time comes when PowerShell needs to share information from those objects with us humans. PowerShell has to take those in-memory data structures and convert them into something a person can view. PowerShell’s formatting system is designed to accomplish that task.

9.1. The time to format

Whenever you construct a command line, those commands all run in a pipeline. What you don’t see is an invisible cmdlet hanging out at the end of every pipeline: Out-Default. It’s hardcoded into the shell, and you can’t get rid of it. You also never have to explicitly call it. Its sole purpose is to kick off the formatting process, using whatever objects happen to be in the pipeline at that point.

That’s an important concept, so let’s linger on it for a second. Consider this command line:

Get-Service | Export-CSV –Path services.csv

9.2. The formatting system

 

9.3. The Format cmdlets

 
 
 

9.4. Eliminating confusion and “gotchas”

 
 
 

9.5. Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest