- Practical Network Automation
- Abhishek Ratan
- 241字
- 2021-07-02 14:53:09
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.
- 電氣自動化專業英語(第3版)
- Hands-On Intelligent Agents with OpenAI Gym
- 亮劍.NET:.NET深入體驗與實戰精要
- 來吧!帶你玩轉Excel VBA
- 條碼技術及應用
- Visual C# 2008開發技術詳解
- Data Wrangling with Python
- STM32嵌入式微控制器快速上手
- 基于32位ColdFire構建嵌入式系統
- Troubleshooting OpenVPN
- 基于神經網絡的監督和半監督學習方法與遙感圖像智能解譯
- 所羅門的密碼
- Machine Learning Algorithms(Second Edition)
- 21天學通Linux嵌入式開發
- 人工智能:智能人機交互