Overview
The most common areas of PowerShell are remote calls, executing scripts on remote machines, monitoring the status of remote machines, such as NLB status, Eventlog,sqlserver database status, and so on.
This article will talk about using the PsExec.exe tool for remote invocation.
1. First Run PowerShell.exe
Double-click PowerShell.exe to agree to licence terms.
2. View PowerShell Help
3. Common Parameters
Computer the computer name, if omitted, executes on the native, and if it is \\*, executes the script on all machines inside the domain
-U remote machine domain user name domain\username
-P remote machine domain user password password
-I specifies that the remote machine is running a session of the desktop of a program, and if not specified, executes in the console session
-s specifies to run the program in the system account
-W Specifies the working path of the running program
program specifies which programs to run, such as Powershell,cmd
4. Example program 1) call directly
1 . \psexec \$MachineIP$DomainUser$Password$WorkPath"$ Workpath\scripts\test.ps1 $Param"
Attention:
1. The "$WorkPath \scripts\test.ps1" file is required on the remote machine disk;
2. PsExec.exe files are not required on the remote machine.
2) Call in Job
1 $Job= Start-job-argumentlist$WorkPath,$MachineIP,$DomainUser,$Password,$WorkPath,$Param-Scriptblock {2 param($WorkPath,$MachineIP,$DomainUser,$Password,$WorkPath,$Param)3Set-location$WorkPath4. \psexec \ \$MachineIP-U$DomainUser-P$Password-h-i 0-s-W$WorkPathPowerShell"$WorkPath \scripts\test.ps1 $Param"5}
5. Example
Path to TEST.PS1: D:\01_360Cloud\02_MyBlogs\PowerShell\Source\test.ps1
TEST.PS1 Script
1 " ABC " 2 Read-host A
PsExec.exe Path: D:\01_360Cloud\02_MyBlogs\PowerShell\Source
Type the following command
1 $WorkPath " D:\01_360Cloud\02_MyBlogs\PowerShell\Source " 2 $WorkPath 3 $WorkPath " . \test.ps1 "
The results are as follows:
Play to PowerShell section II-"Remote invocation with PsExec"-Technology & Sharing