Learning PowerShell, we don't expect to get everything done through C # programming, we should remember Cmd.exe or the precious asset that the batch has left us--by calling an external program to solve the problem. Call the external program, it is necessary to manage the process, this is the article to introduce.
1, get-process, return process.
get-process [-id], get by PID
Get-process-name, by Process name
Get-process-inputobject, incoming parameters
Example: Get-process-name MMC, which displays all MMC processes.
2, Start-process, start a process
Syntax: Start-process-filepath < path to executable file >-argumentlist < parameter list >
Description: Support in PowerShell v2.0 above!
3, stop-process, stop one or more running processes.
stop-process [-id], stopping the process of the specified PID array
Stop-process-name, stop a list of process names
Stop-process-inputobject, stops all processes in an array of process types.
such as: Stop-process-name Notepad, this function can also be implemented as follows:
$pro = Get-process-name Notepad; $pro. Kill (); or (Get-process-name notepad). Kill ();
Windows provides a Taskkill.exe program through which you can also stop programs: taskkill/f/im Java.exe
With this command, when we are going to end the java.exe running in Cmd.exe, we only end java.exe, and this time the CMD will be ended.
4. Call PS1 or batch file (invoke-expression) using dot (.)
Grammar:.
Description: You can call an existing PS1 file in the PowerShell interactive environment and in the PS1 file, using the dot (.) as the caller. I have tried using Invoke-item, as if I hadn't started it.
You can also use the invoke-expression (alias IEX) command for two different uses:
Copy CodeThe code is as follows:
C:\ps>invoke-expression-command "C:\ps-test\testscript.ps1"
C:\ps> "C:\ps-test\testscript.ps1" | Invoke-expression
Note: You can use PS1 here, or you can use other executable batch files, such as. cmd,. bat, and so on.
5. Open the file by default (Invoke-item)
Syntax: Invoke-item < file path to open >
Example: Invoke-item "C:\1.txt" #将使用txt文件的默认打开工具 (i.e. Notepad) Open C:\1.txt
Note: The file must exist, otherwise the "This path does not exist" error is reported.
6. Use & Invoke Program
Syntax:& < executable file path > [< parameter list;]
Example:
Copy CodeThe code is as follows: $execPath = "D:\progra~1\flashfxp\flashfxp.exe"
$execArgs = "-upload ftp://u:[email protected]:21"
$execArgs = $execArgs + "-remotepath=" "/" "
$execArgs = $execArgs + "-localpath=" "d:\123\" "
& $execPath $execArgs. Split ()
7. Use CMD to perform DOS internal or external commands
Description: There are many DOS commands that are used by the cmdlet alias, so if you use it as before, you may find that the parameters are incorrect. In order to be compatible with the usage in the previous batch, you can use CMD/C to invoke DOS internal or external commands.
Syntax: cmd/c
Example: cmd/c del/s/q d:\testdir\testsubdir\*.*
Example of calling external program and process action commands in PowerShell