0% found this document useful (0 votes)
18 views25 pages

Formatting Output

Module 5 focuses on formatting output in PowerShell, covering basic and advanced formatting techniques, including the use of lists, tables, and custom columns. It also discusses redirecting formatted output to various destinations and the use of grid views for displaying data. The module includes demonstrations and a lab exercise to reinforce learning about producing formatted output for management reports.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views25 pages

Formatting Output

Module 5 focuses on formatting output in PowerShell, covering basic and advanced formatting techniques, including the use of lists, tables, and custom columns. It also discusses redirecting formatted output to various destinations and the use of grid views for displaying data. The module includes demonstrations and a lab exercise to reinforce learning about producing formatted output for management reports.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Module 5

Formatting Output
Module Overview

Using Basic Formatting


Using Advanced Formatting
• Redirecting Formatted Output
Lesson 1: Using Basic Formatting

Default Formatting
Wide Lists
Lists
Tables
• Demonstration: Basic Formatting
Default Formatting

• Decides how to display output based upon


the object type of the first object in the
pipeline
• Uses a set of XML view definitions and XML
type extensions to decide what to display,
and how to display it
• You can manipulate these defaults by
providing additional XML files, although
creating those files is beyond the scope of
this course
Wide Lists

Get-Service | Format-Wide

Get-Process | Format-Wide –Property


ID

Get-Process | Format-Wide –Col 5

Get-Process | FW -AutoSize
Lists

Get-Service | Format-List –Property *

Get-Process | FL –Prop Name,ID

Get-Service | FL
Name,Status,DisplayName
Tables

Get-Process | Format-Table –Property


ID,Name

Get-Process | FT *

Get-Service | FT Name,Status –AutoSize -


Wrap
Demonstration: Basic Formatting

In this demonstration, you will see how to use


the basic features of the three main
formatting commands
• Using Format-Wide
• Using Format-List
• Using Format-Table
Lesson 2: Using Advanced Formatting

Custom List Entries and Columns


Demonstration: Custom Table Columns
Sorted and Grouped Tables
Demonstration: Grouped Tables
• Select or Format?
Custom List Entries and Columns

• Extension of the calculated property


syntax used by Select-Object:

Get-Process |
Format-Table -Property Name,ID,@{n='VM(MB)';

e={$PSItem.VM /
1MB};
formatString='N2';
align='right'} -
AutoSize
Demonstration: Custom Table Columns

• In this demonstration, you will see how to


create custom table columns by using
Format-Table
Sorted and Grouped Tables

• –GroupBy parameter of format commands


accepts a property name
• Produces a new set of headers each time
that property’s value changes
• For best results, first sort the objects on
the same property

Get-Service | Sort Status | Format-Table –GroupBy


Status
Demonstration: Grouped Tables

• In this demonstration, you will see how to


display grouped table output
Select or Format?

• Select-Object and the format commands,


especially Format-Table, have
overlapping functionality

• Use Select if you need to pipe objects to


another command to sort, export, filter,
enumerate, and so on
• Use formatting if you are finished
manipulating the objects and are ready to
display output on the screen
Lesson 3: Redirecting Formatted Output

The Output of a Format Command


Demonstration: Examining Formatting
Output
Redirecting Formatted Output
Demonstration: Redirecting Formatted
Output
Using Grid Views
• Demonstration: Using Grid Views
The Output of a Format Command

• Only a small number of commands can


accept the specialized objects produced by
the format commands

• A good rule to remember is format right,


meaning that format commands must
come at the end of the command line
• There are only a couple of exceptions
Demonstration: Examining Formatting
Output

In this demonstration, you will see how


format commands produce a specialized
kind of object
• Examine the output of a command
• Examine the output of a format command
Redirecting Formatted Output

• Three commands can follow a format


command to redirect output:
• Out-Host – to the screen
• Out-File – to a text file
• Out-Printer – to a printer

• These commands can follow any format


command on the pipeline
• The redirected content will look exactly as
it would have looked on the screen
Demonstration: Redirecting Formatted
Output

• In this demonstration, you will see how to


redirect formatted output to a file
Using Grid Views

• Out-GridView displays objects in a


sortable, filterable grid
• Does not accept formatted output
• Only available if the Windows PowerShell
ISE host is installed on the computer
Demonstration: Using Grid Views

• In this demonstration, you will see how to


use the Out-GridView command
Lab: Formatting Output

Exercise 1: Formatting Command Output


• Exercise 2: Reproducing Specified Output

Logon Information

Virtual Machines: 10961B-LON-DC1, 10961B-LON-C


User Name: ADATUM\Administrator
Password: Pa$$w0rd

Estimated Time: 45 minutes


Lab Scenario

Your organization has specific criteria for


the content and appearance of
management reports. You have to write
several commands that produce formatted
output so that the output can be used in
management reports.
Lab Review

• If you redirected formatted output to a file,


is there a command that would let you
attach that file to an email message?
Module Review and Takeaways

Review Question(s)
Real-world Issues and Scenarios
Best Practice
• Common Issues and Troubleshooting Tips

You might also like