官术网_书友最值得收藏!

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
主站蜘蛛池模板: 镇沅| 通道| 获嘉县| 五家渠市| 富宁县| 惠东县| 遂昌县| 苏州市| 刚察县| 五莲县| 尚志市| 布拖县| 闵行区| 阆中市| 松溪县| 玛纳斯县| 安丘市| 安岳县| 鸡东县| 岱山县| 马公市| 得荣县| 绥江县| 商南县| 麻城市| 噶尔县| 隆德县| 图片| 葫芦岛市| 开化县| 东乡族自治县| 胶南市| 定陶县| 高青县| 通辽市| 五峰| 迁西县| 南投市| 盐津县| 灵璧县| 陇川县|