In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how the pipes in PowerShell work. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Pipeline model
As the name implies, pipes are pipes that connect things to form channels. On the face of it, a pipe is a string of commands connected by a pipe symbol (|). From a functional point of view, a pipeline is like a pipeline, passing the results of the previous process to the next as input. Commands connected by pipes are executed from left to right, and the results are output to the console. Previous pipe streams sent strings, or expressions that could be formatted as strings, while PowerShell's pipe streams could transfer objects.
How do pipes work in PowerShell?
PowerShell's pipeline, which can pass objects, is a huge step forward. At this point, the pipeline has the smell of function calls. The caller can pass complex objects, and the receiver needs to match the types of objects. Incorrect matching will lead to errors in command execution. But there are exceptions. PowerShell pipes can be passed not only by the whole object, but also by attribute names, which greatly improves the availability and processing power of the pipeline. This allows us to use pipes to pass some of the properties of the object in the case of a type mismatch.
Examples of pipeline use
In PowerShell, there are some commands specially designed for the pipeline, such as get-member, sort, measure, etc., and some commands are not specially designed for the pipeline, but shine in the pipeline. Here are some examples of the most commonly used commands:
Select
Using the select command in pipes is as common as using dir in Cmd. Without looking at the detailed syntax of the select command, you can write out the most common ways to use select. As follows:
Dir | select name,LastWriteTime
This command displays the names of the files and subfolders in the current folder and the date they were modified.
Where
The where command is used for filtering, which can be abbreviated to?. Examples are as follows:
Dir |? {$_ .mode-like "d*"} | select name,LastWriteTime
This command can display only the subfolders of the current folder, not files.
Foreach
Foreach can handle each object passed, which can be abbreviated to'%'. Examples of use are as follows:
Dir |? {$_ .mode-notlike "d*"} |% {echo "The size of file'$($_ .name)'is $_ .length"}
The result of this command is to output information like "The size of file 'myScript.ps1' is 1520", one line per file.
This is the end of the article on "how pipes in PowerShell work". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.