PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
No Result
View All Result
Home Powershell Fundamentals

3 Proven ways to Learn Pipeline in Powershell

themeanmachine19@gmail.com by [email protected]
July 4, 2021
in Powershell Fundamentals
0
Pipeline in Powershell
Share on FacebookShare on Twitter

You might also like

Powershell filter

Powershell filter: Using where-object and select-object (2021)

September 9, 2021
Function in PowerShell

A step-by-step guide for function in Powershell in 2021

September 1, 2021
Pipeline in Powershell is one of the easy concepts but yet effective. In this tutorial, we will learn how to use the Pipeline correctly and making our scripts tidy in Powershell.
Pipeline in Powershell

What is Pipeline?

Windows Powershell runs commands in a pipeline. Each command line we see is a pipeline. A pipeline can contain one or more commands, with multiple commands separated by a vertical pipe character ” | ” .

Commands execute from left to right, with the output of each command being piped or passed to the command after it. The output of the last command in the pipeline is what appears on your screen.

				
					Get-Service #it is a single commad pipeline

#Multicommand pipelines looks similar
Get-Service| out-file servicelist.txt
				
			

Get-Service |out-file servicelist.txt doesn’t show any output do you know why?

Well, it stores the output directly to the text file mentioned after the pipeline. If you do understand this then you are on the right path.

Selecting, Sorting and Measuring objects

You must have understood the concept of Pipelining. Now let’s understand how we can use pipeling with select-object, sort-object, and measure-object. Let’s see how we can use the above pipelines with some examples.

Sorting-Objects on a Property

Sort-Object can re-sort objects in the pipeline.

				
					Get-Service | Sort-Object Name Descending
				
			

Similarly, you can try Ascending in the above and try the output. 

Measuring-Object on a Property

Measure-Object can measure objects in the pipeline. We need to add -Property to specify the single numeric property. After -Property, we can add the following.

  •  -Average to calculate an average.
  • -Maximum to display the largest value.
  • -Minimum to display the smallest value.
  • -Sum to display the sum.

The Output will be a measurable or measurement object but not whatever we piped in. Let’s check out few examples you can try on your PC.

				
					Get-Service | Measure-Object

Get-process | Measure-Object

2,0,5,6 | Measure-Object -Sum

2,0,5,6 | Measure-Object -maximum
				
			

Unable to delete unwanted software or software don't get cleaned up fully ?

Special Uninstaller is a great application to delete or uninstall software that is not required. The plus point is it clears every file and registry key associated with the application. It is available for Free and Premium with 24×7 support. Do try this application out.

Selecting a Subset of an Object

Select-object has no intelligence whatsoever and as the name suggests it is used for selection let’s check what it is actually used in and how we can use it in a script.

Below are some parameters which can be used with Select-Object.

  • -First for the beginning.
  • -Last for the end.
  • -Skip to skip a number of rows before selecting.

We cannot specify any criteria for choosing any specific rows. Let’s check out some examples we can try on our PC.

				
					Get-Service | select-object -first 10

Get-process | select-object -first 10


				
			

This is one way of using Select-Object or Select, let’s check out another way we can use Select-object.

				
					get-service |select-object -property Name -first 10



				
			

In this above example, we are selecting a specific property i.e. we have chosen Name and also selected the first 10 results. Similarly, we can try the same with other examples.

Conclusion

In this tutorial, we have understood what is Pipeline in Powershell, why to use it and how we can use it. We have also gone through selecting, sorting, and measuring objects and where we can use them with examples. You can try each example on your PC but make sure you have Powershell installed in it. Let’s meet you in our next blog soon and I hope you have understood something from this today.

close

DON’T MISS A POST

Keep up to date with PowershellGuru

Powershell Blogs

PowershellGuru provides the best PowerShell scripts available that can be used and download freely. Do Check our blogs to get updated regularly.

Check your inbox or spam folder to confirm your subscription.

themeanmachine19@gmail.com

[email protected]

Related Stories

Powershell filter

Powershell filter: Using where-object and select-object (2021)

by [email protected]
September 9, 2021
0

Step-by-step guide for function in PowerShell. Function in Powershell. Function with the return value. Function scope. Function examples.

Function in PowerShell

A step-by-step guide for function in Powershell in 2021

by [email protected]
September 1, 2021
0

Step-by-step guide for function in PowerShell. Function in Powershell. Function with the return value. Function scope. Function examples.

error handling in powershell

Understanding Error handling in Powershell [2021]

by [email protected]
August 20, 2021
0

Error handling in Powershell. Error handling in Powershell . Error handling in Powershell. PowershellGuru. Try block. Throw block. Catch block....

Useful Powershell commands

10 Useful Powershell commands that everyone should know

by [email protected]
August 10, 2021
0

Powershell cmdlets. Powershell cmdlets list. Powershell cmdlets example. Get-process. Get-command. Set-executionpolicy. Clear-history. Stop-process.

Next Post
Useful Powershell commands

10 Useful Powershell commands that everyone should know

Please login to join discussion

Recommended

Detecting Log4j vulnerable servers using PowerShell

Detect Log4j vulnerable servers using PowerShell

December 29, 2021
Add users to multiple groups using PowerShell

Add users to multiple groups using PowerShell from CSV (2021)

November 15, 2021

About

Dhrub Bharali

PowerShell Enthusiast

Dhrub is hardcore Powershell enthusiast, he has wriiten more than 100 powershell scripts and he is the sole owner of PowerShellGuru.

Follow Us

Popular Story

  • Installing software remotely using powershell

    Easy way to install software remotely using PowerShell (2021)

    827 shares
    Share 331 Tweet 207
  • Detect Log4j vulnerable servers using PowerShell

    753 shares
    Share 301 Tweet 188
  • How to find NTP Server using PowerShell?

    738 shares
    Share 295 Tweet 185
  • Get-LocalGroupMember: Find Local admin using PowerShell (2021)

    728 shares
    Share 291 Tweet 182
  • Get installed software list quickly using PowerShell (2021)

    695 shares
    Share 278 Tweet 174
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login