Play to PowerShell section II-"Remote invocation with PsExec"-Technology & Sharing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.