Question: Format and filter output using Windows PowerShell In this step, you will learn how to use command parameters and cmdlets to filter data. Also, you
Format and filter output using Windows PowerShell
In this step, you will learn how to use command parameters and cmdlets to filter data. Also, you will learn how to format the displayed output.
1. To view a list of services installed on the computer, at the Windows PowerShell command prompt, type the following command, and then press ENTER.
PS >Get-Service
Windows PowerShell provides a complete set of verbs to query and manipulate services, including Get, New, Restart, Resume, Set, Start, Stop, and Suspend. To view a list of service related commands type Get-Command -Noun Service.
2. Enter the following to view the status of the Spooler service:
PS >Get-Service Name Spooler
3. Enter the following command to obtain the same result as the previous step.
PS >Get-Service Spooler
4. Type the following command, and then press ENTER to view a list of all services that begin with M.
PS >Get-Service M*
The status of all the services beginning with M is shown.
Many cmdlets allow the use of wildcards. You can use the wildcard to filter the results to a subset of all result
5. Enter the following to see the same list of services. This time, the output is shown in list format.
PS >Get-Service M* | Format-List
In this example, there are two commands separated by a pipe (|) character. This means that the output of the first command is used as the input to the second command.
6. Enter the following to see the same output, this time shown in a custom format.
PS >Get-Service M* | Format-Custom
The status of all services beginning with M will be shown in the custom format.
7. Type the following command, and then press ENTER to view all the running services that begin with M.
PS >Get-Service M* | Where-Object {$_.Status -eq "Running"}
Only services in a running state are shown this time.
In this command: Where-Object is a command for performing a filter on the input. { } are delimiters for Windows PowerShell code blocks. $_ refers to the input object (all services that begin with M). -eqspecifies that the left-hand argument, in this case the Status property ($_.Status), will be compared for equality against the right-hand argument, the value Running.
8. To view all the stopped services that begin with M, type the following command, and then press ENTER.
PS >Get-Service M* | Where {$_.Status -eq "Stopped"}
Only those services that are stopped are shown.
USE WINDOWS POWERSHELL SHOW INPUT AND OUTPUT AS WELL AS A SCREEN SHOT FOR EVERY STEP MADE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
