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

Interacting with local machines

As mentioned earlier, PowerShell is deeply integrated with Windows at all levels. Let's look at an example of certain processes (system or PowerShell processes from Microsoft), running locally on the Windows machine:

Get-Process `
| Where-Object {$_.company -like ‘*Microsoft*’}`
| Where-Object {($_.ProcessName -like ‘*System*’) -or ($_.ProcessName -like ‘*powershell*’)}`
| Format-Table ProcessName, Company -auto

The output is as follows (when executed from PowerShell console):

PS C:\Users\abhishek.ratan> Get-Process `
| Where-Object {$_.company -like ‘*Microsoft*’}`
| Where-Object {($_.ProcessName -like ‘*System*’) -or ($_.ProcessName -like ‘*powershell*’)}`
| Format-Table ProcessName, Company -auto
ProcessName Company
----------- -------
powershell Microsoft Corporation
powershell_ise Microsoft Corporation
SystemSettings Microsoft Corporation
SystemSettingsBroker Microsoft Corporation

As we can see in this example, another feature of PowerShell is the piped command format support (|). Similar to Unix, a piped command in PowerShell is used to take objects, output from one cmdlet, easily send it to another cmdlet, and so on, until we granularize to a final output.

In this example, we took the output of Get-Process (which is a full process dump of our local machine), and filtered out the processes running from Microsoft Corporation. Then we further refine it to show only those processes that have the System or powershell in the name. The final output is piped to a tabular format with ProcessName and Company as the table header.

主站蜘蛛池模板: 社会| 黄龙县| 屯留县| 长兴县| 岳阳市| 伽师县| 辽阳市| 泰安市| 神农架林区| 环江| 南皮县| 武陟县| 华安县| 秦皇岛市| 平凉市| 大渡口区| 淅川县| 友谊县| 凤山市| 班玛县| 公主岭市| 白河县| 永康市| 泽库县| 塔河县| 神木县| 友谊县| 江源县| 荥阳市| 唐海县| 郯城县| 重庆市| 徐州市| 宣恩县| 龙陵县| 乌恰县| 鄂托克旗| 阳谷县| 谷城县| 兴山县| 如东县|