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

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.

主站蜘蛛池模板: 正定县| 富平县| 民乐县| 裕民县| 麟游县| 桐庐县| 武鸣县| 攀枝花市| 满洲里市| 扶沟县| 班玛县| 九台市| 西林县| 洛浦县| 五华县| 盐池县| 铁岭县| 丹棱县| 泽州县| 富阳市| 明光市| 平南县| 福鼎市| 庆安县| 安仁县| 孝昌县| 双峰县| 藁城市| 敦煌市| 湘潭县| 永年县| 邵阳市| 开远市| 吴旗县| 新竹县| 南通市| 曲阳县| 宜君县| 扶沟县| 布拖县| 兴化市|