The last time we managed Windows Services, learned how to get services on local and remote computers, and looked for specific services, started, ended, paused, and restored services. Next, let's take a look at another core content in Windows Management: process management.
Test script download
All scripts in this series areWindows Server 2008 r2 datacenter (powershell 2.0) + powergui Script Editor Free Edition x64.
Processes are the basis of the operating system structure and are being executedProgramAn instance of a program running on a computer. It is an entity that can be allocated to the processor and executed by the processor. It is displayed by execution in a single order. It is an activity unit described by the current status and a group of related system resources.
PowershellProcess-related commands in5Items:
Get-Process
Start-Process
Stop-Process
Debug-Process
Wait-Process
- First, check the members of the Process object:
Get-Process|Get-member
Running result:
As you can see, get-process returns an instance of the. NET object system. Diagnostics. process. Five aliases are very important:
Handles |
Number of handles opened by the Process |
NPM |
The amount of non-Paging memory in use by the process, in kilobytes. |
PM |
The amount of paging memory that the process is using, in kilobytes. |
VM |
The amount of virtual memory that the process is using, in MB. The Virtual Memory includes storage of paging files on the disk. |
WS |
The size of the process working set, in kilobytes. Working sets include pages of memory recently referenced by processes |
View the top 10 processes that occupy the most paging memory:
Get-Process|Sort
PM
-Descending|Select
-First10
Running result:
Obtain all processes that occupy more than 50 MB and sort them in reverse order:
Get-Process|Where{$ _. Ws-GT50 MB} |Sort
WS
-Descending
Running result:
In powershell 2.0, you can also view processes on a remote computer.
As shown in, the IP address of the computer in the VM is 192.168.200.132:
Get-Process
-Computername
192.168.200.132
Running result:
- Start a process. In powershell 2.0, start-process can be used on a local computer to start a process:
Start-Process
Iexplore.exe
Start-process can only be used on local computers.
Running result:
Note: The 32-bit program is started by default. To start a 64-bit program, you must add the-filepath parameter to specify the location of the 64-bit program:
Start-Process
-Filepath
"C: \ Program Files \ Internet Explorer \ ipolice.exe"
Running result:
- End the process.
Start a notepad process, record it, and then sleep for 3 seconds, and end the process:
$ Notepad
=[System. Diagnostics. Process]:Start("Notepad")
[System. Threading. Thread]:Sleep(3000)
Stop-Process
-ID
$ Notepad.ID
Running result:
In 3 seconds, the notepad will automatically shut down.
4. Obtain the directory information of the word process:
(Get-Process
Winword). Mainmodule
Running result:
Obtain the database information that the Excel process depends on
Start-Process
Excel
(Get-Process
Excel). Modules
Stop-Process
-Name
Excel
Running result:
Get process metadata:
Get-Process|SelectCompany, product, productversion
Running result:
The Google Chrome version is not correctly identified.J
Set process priority:
Each process has a corresponding priority, and the priority determines when it runs and how much it receives CPU Time. Total final priorities 32 Level, from 0 To 31 Is called the basic priority level ( Base Priority Level ). The System Schedules processes based on different priorities, 0-15 A level is a common priority. The priority of a process can be dynamically changed. A high-priority process takes precedence over running. only low-priority processes run when they are not running, processes with the same priority run in turn based on time slices. 16-31 The level is the real-time priority. The biggest difference between the real-time priority and the general priority is that the running of processes with the same priority is not rotated by time slice, but is controlled by the processes that run first. CPU If it does not take the initiative to give up the control, the process at the same level or low priority will not be able to run.
It can be read and written by the priorityclass attribute. Valid Value List: Normal, idle, high, realtime, belownormal, abovenormal.
$ Process
=
Get-Process
Winword
Write-host
$ Process.Priorityclass
$ Process.Priorityclass
=
"High"
Write-host
$ Process.Priorityclass
Running result:
It can be seen that the priority of word is changed from normal to high.
5. debugging process:
Debug-Process
-Name
Winword
A prompt window is displayed, showing you how to select the debugger:
Wait for the process to end
Wait-Process
-Name
Notepad
The script input window waits until the process ends:
After closing the notepad window:
Summary:
This is a simple management operation on Windows processes. Compared with Windows Services, process management is relatively simple, mainly to view processes and set process priorities, but the importance is the same. Processes and services are the basic functions of windows. running programs are maintained. Improper configuration may cause system instability. In addition, powershell 2.0 enhances the remote processing capability and facilitates remote management operations. Next time, let's take a look at the operations related to the Registry.