0% found this document useful (0 votes)
12 views11 pages

PowerShell Formatting Lab Exercises

The document provides lab instructions for using the formatting subsystem in PowerShell, including exercises on displaying calculated properties, limiting displayed columns, and viewing objects via HTML. Each exercise outlines specific tasks to retrieve and format data, such as processes and services, for better visualization and analysis. The lab is designed for system administrators to assist developers by presenting data in a user-friendly manner.

Uploaded by

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

PowerShell Formatting Lab Exercises

The document provides lab instructions for using the formatting subsystem in PowerShell, including exercises on displaying calculated properties, limiting displayed columns, and viewing objects via HTML. Each exercise outlines specific tasks to retrieve and format data, such as processes and services, for better visualization and analysis. The lab is designed for system administrators to assist developers by presenting data in a user-friendly manner.

Uploaded by

shrikantnpar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab Instructions: Understanding and Using the

Formatting System
Module 2

Contents:
Lab: Using the Formatting Subsystem
Exercise 1: Displaying Calculated Properties
Exercise 2: Displaying a Limited Number of Columns
Exercise 3: Displaying All Properties and Values of Objects
Exercise 4: Viewing Objects via HTML
Exercise 5: Displaying a Limited Number of Properties
Exercise 6: Displaying Objects Using Different Formatting
Exercise 7: Displaying a Sorted List of Objects
Lab: Using the Formatting Subsystem
Estimated time: 20 minutes
You are a system administrator for a company and work with a team of [Link],
some users have complained about an in-house developed application. The developers have
asked you to monitor the processes associated with the troubled application and let them have
easy access to the data. You have decided to provide them with that information via an HTML-
based page so they can easily view the information in a Web browser. You also want to
customize your view of this information as you view it in the PowerShell console.

Lab Setup
For this lab, you will use the available virtual machine environment. Before you begin the lab,
you must:
1. Start the AD virtual machine. You don’t need to log on but wait until the boot process is
complete.
• Username: CONTOSO\administrator
• Password: Pa$$w0rd
2. Open a Windows PowerShell session as Administrator.
Exercise 1: Displaying Calculated Properties

Scenario
You need to check the status of processes on your server, and you want to display their status
and also show custom properties in a table [Link] main tasks for this exercise are as follows:
1. Retrieve a list of processes.
2. Display a table of objects.
3. Select the properties to display.
4. Use calculated properties to show a custom property.

� Task 1: Retrieve a list of processes


• Open Windows PowerShell and retrieve a list of running processes.

� Task 2: Display a table of objects


• Show the list of running processes formatted as a table.

� Task 3: Select the properties to display


• Show the list of running processes formatted as a table showing only the CPU, Id, and
ProcessName values.

� Task 4: Use calculated properties to show a custom property


• Show the list of running processes formatted as a table showing the CPU, Id, ProcessName
values, and a custom property named TotalMemory, which is the sum of the physical and
virtual memory used for each process.

Hint: Just add the values together—don’t be concerned if one is displayed in KB and
the other in MB.
Results: After this exercise, you will have displayed the CPU, ID and ProcessName values of all
the running processes. You also will have created a custom property adding the physical and
virtual memory using calculated properties.
Exercise 2: Displaying a Limited Number of Columns
Scenario
You need to display a list of services on your systems. You need to filter out some of the
columns that you don’t need when reviewing the status of the [Link] main tasks for this
exercise are as follows:
1. Retrieve a list of services.
2. Display a specific number of columns from a collection of objects.

� Task 1: Retrieve a list of services


• Retrieve a list of services.

� Task 2: Display a specific number of columns from a collection of objects


• Retrieve a list of services and display only the Status and Name properties.

Results: After this exercise, you will have displayed a specific number of columns from all the
installed services instead of displaying all their default properties.

Exercise 3: Displaying All Properties and Values of Objects


Scenario
You often retrieve a list of processes from your systems and need to display all the properties
and values of the services and not just the default values normally [Link] main tasks for this
exercise are as follows:
1. Retrieve a list of processes.
2. Display every property and value for all the objects.

� Task 1: Retrieve a list of processes


• Retrieve a list of processes.

� Task 2: Display every property and value for all the objects
• Retrieve a list of processes and display all their properties and values.

Results: After this exercise, you will have displayed all of the properties of all of the running
processes instead of displaying only their default properties.

Exercise 4: Viewing Objects via HTML


Scenario
You have been asked by the development team to post a log of entries from one server’s
application event log. You have decided to automate the gathering of the information and are
posting it on an internal Web site for the developers to [Link] main tasks for this exercise
are as follows:
1. Retrieve a list of event log entries.
2. Convert a list of event log entries to HTML.
3. Use a custom title for an HTML page.
4. View an HTML page in the default Web browser.

� Task 1: Retrieve a list of event log entries


• Retrieve the newest 25 events from the Windows Application event log.

� Task 2: Convert a list of event log entries to HTML


• Retrieve the newest 25 events from the Windows Application event log and convert the events
as HTML and save the results to a file.

� Task 3: Use a custom title for an HTML page


• Retrieve the newest 25 events from the Windows Application event log and convert the events
as HTML file while changing its title to Last 25 events and save the results to a file.

� Task 4: View an HTML page in the default Web browser


• View the resulting file from the previous task in the default Web browser (Hint: use Invoke-
Item).

Results: After this exercise, you will have displayed a customized HTML page that contains a
listing of the 25 newest events from the Windows Application event log.

Exercise 5: Displaying a Limited Number of Properties


Scenario
You need to review the length of certain files in a particular directory and want to use
PowerShell to accomplish this task. The main tasks for this exercise are as follows:
1. Display a list of files from a selected folder.
2. Display a table with several different file properties.

� Task 1: Display a list of files from a selected folder


• Retrieve a list of all the files that start with au and end with .dll from the
C:\Windows\System32 directory.

� Task 2: Display a table with several different file properties


• Retrieve a list of all the files of that start with au and end with .dll from the
C:\Windows\System32 directory and display the Name, Length and Extension properties using
a table.

Results: After this exercise, you will have displayed a table containing the Name, Length and
Extension properties of all the files in C:\Windows\System32 that start with au and have the
extension .dll.

Exercise 6: Displaying Objects Using Different Formatting


Scenario
You often use PowerShell to verify the status of processes and services and want to know how to
change the way that the information is displayed in the console. The main tasks for this exercise
are as follows:
1. Retrieve a list of services.
2. Display a table showing only a few specific properties.
3. Display a table by eliminating any empty spaces between columns.

� Task 1: Retrieve a list of services


• Retrieve a list of services.

� Task 2: Display a table showing only a few specific properties


• Retrieve a list of services and display only the DisplayName, Status and DependentServices
properties using a table.

� Task 3: Display a table by eliminating any empty spaces between columns


• Retrieve a list of services and display only the DisplayName, Status and DependentServices
properties using a table and eliminating any empty spaces between columns.

Results: After this exercise, you will have displayed a table of all the installedservices by
displaying only the DisplayName, Status, and DependentServices properties. You have also
removed any empty spaces between each column.

Exercise 7: Displaying a Sorted List of Objects


Scenario
You use PowerShell to view the status of processes and services and want to modify how some
of the columns display data and even possibly create new customized [Link] main tasks
for this exercise are as follows:
1. Retrieve a list of services.
2. Display a table while sorting a specific property.

� Task 1: Retrieve a list of services


• Retrieve a list of services.

� Task 2: Display a table while sorting a specific property


• Retrieve a list of services and display a table showing the services by sorting on the Status
property.

Results: After this exercise, you will have displayed a table of the installed services sorted by
their Status property.

Common questions

Powered by AI

A system administrator can use PowerShell to create a custom property by retrieving a list of running processes and formatting the output as a table. By selecting the CPU, Id, and ProcessName values, the administrator can also introduce a custom property named TotalMemory, derived by calculating the sum of the physical and virtual memory for each process. The physical and virtual memory values are summed without worrying about differing units such as KB and MB .

Converting event log entries to HTML format allows for easy dissemination and viewing through web browsers, enhancing accessibility and usability, especially for development teams requiring regular log reviews. The steps involved include retrieving the newest 25 events from the Windows Application event log, converting them into an HTML format using PowerShell commands, assigning a custom title such as 'Last 25 events', saving the results to a file, and then opening this file in a default web browser for easy access .

Eliminating empty spaces between columns in PowerShell can lead to a more compact and readable format, which is especially beneficial when displaying data on limited screen real estate or when generating reports. The process involves retrieving a list of services and displaying them in a table format while configuring the table to exclude unnecessary whitespace between columns, thus presenting a dense and efficient display of information .

The benefits of filtering displayed columns include focused analysis, improved readability, and relevance of data when assessing file properties, which is particularly useful when dealing with large datasets. However, limitations might include the potential oversight of critical data not displayed due to column filtering, possibly leading to incomplete analysis when investigating file issues .

An administrator might automate the conversion of event log entries to an HTML file to streamline workflow, reduce manual error, and ensure consistent and timely updates for log reviews. The key benefits include improved efficiency, as logs are formatted and available without manual intervention, and enhanced accessibility, as they can be reviewed directly in web browsers by any team member needing access, ensuring that critical information is always current and easily digestible .

A system administrator can sort a list of services in PowerShell by first retrieving the list of services and using a command to order the list by a specific property, such as Status. This allows the administrator to quickly identify and categorize services based on their operational status, which can be useful for diagnosis and reporting .

Displaying all properties and values of processes in PowerShell allows system administrators to have a comprehensive view of every aspect of process behavior and resource usage. This enhancement in system monitoring provides administrators with detailed insights enabling them to diagnose issues more accurately, perform in-depth analysis, and make informed decisions about system optimization and resource allocation .

To view an HTML page generated from event log entries in a web browser using PowerShell, you start by retrieving the newest events from the Windows Application event log. Convert these entries into an HTML file, optionally customize the title, and save the file to disk. Finally, use the 'Invoke-Item' cmdlet in PowerShell to open the HTML file in the system's default web browser, allowing for easy inspection and analysis .

Strategies to customize memory usage display in PowerShell include creating calculated properties that combine physical and virtual memory into a single, easily comparable metric, using table formats to only display relevant memory properties, and potentially converting complex memory data into more meaningful units or forms for easier comprehension and decision-making by non-technical stakeholders .

A system administrator might choose to display a limited number of properties to focus specifically on essential data, reducing clutter and improving ease of analysis. For example, when managing services, the administrator can retrieve a list of services and display only crucial properties like Status and Name. By filtering out unnecessary data, the administrator can quickly assess service statuses and names without being overwhelmed by irrelevant information .

You might also like