- Microsoft Exchange Server PowerShell Essentials
- Biswanath Banerjee
- 260字
- 2021-07-16 13:04:57
Using pipelines
A pipeline is a series of cmdlet statements connected through the pipeline (|
) character (ASCII 124). Pipelines are used to send the output objects from one command as an input to another command. This can be used in scripts and console to build complex statements.
The output of Get-Service
is piped to more
command that displays information one screen at a time:
Get-Servince | more
You can use pipelines to build complex queries. For example, the following example will get the output of the Get-Service
cmdlet and pipe it to the Where-Object
cmdlet that will filter the services whose names match the MSExchange text, and the status is set to Running. The logical and
operator is used in this case to combine the two conditions:
Get-Service | Where-Object {($_.Name –like "MSExchange*") –and ($_.Status –eq "Running")}
So far, we saw how to take output from one command and feed it into the next one. Now, let's take it further by adding one more piping. The following statement will get the output of the Get-Service
cmdlet and pass it to Where-object
where it will filter it for Exchange services, which are stopped, and then it will pass the output using another pipeline to Start-Service
cmdlet. So, using this one-line command, you can check which Exchange Services are not running and start them. We have used the—autosize parameter to format the output based on the number of columns and their sizes:
Get-Service | Where-Object {($_.Name –like "MSExchange*") –and ($_.Status –eq "Stopped")} | Start-Service
- GAE編程指南
- What's New in TensorFlow 2.0
- Visual Studio 2012 Cookbook
- 數(shù)據(jù)結(jié)構(gòu)和算法基礎(chǔ)(Java語言實(shí)現(xiàn))
- Object-Oriented JavaScript(Second Edition)
- PostgreSQL Replication(Second Edition)
- ArcGIS By Example
- 高級語言程序設(shè)計(jì)(C語言版):基于計(jì)算思維能力培養(yǎng)
- Hands-On Natural Language Processing with Python
- HTML5+CSS3 Web前端開發(fā)技術(shù)(第2版)
- Python深度學(xué)習(xí)原理、算法與案例
- FPGA嵌入式項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Scala Functional Programming Patterns
- 新手學(xué)ASP.NET 3.5網(wǎng)絡(luò)開發(fā)
- JavaScript程序設(shè)計(jì)實(shí)例教程(第2版)