You are not logged in.

#1 21 Oct 2020 05:09

CameronY0
Member
Registered: 20 Oct 2020
Posts: 1

PowerShell Remote Execution Question(s)

Hi Everyone,
Has been ages since I last wrote a script for any platform, but have been tasked with one in PowerShell recently.

In brief:
Running from Server-A (running PS 4.0), I have a listing of server names (700-800) to upload packages to and then execute a PS1 script on the remote server (Server-X).

Problem #1:
How best should I execute the remote .ps1 script (on Server-X) and can this be done in a Unix style background mode '&'?
The remote .ps1 script may take only a few minutes on some servers and take hours on others - hence seeking for a background mode capability.

I was this morning attempting to use ... 

Start-Process -Filepath "$PSExec" -ArgumentList "\\$Server -h -d $RmtFldr2\test-exec.ps1"

But that isn't working as I'd hoped.

Problem #2:
Am finding that some of the servers I need to connect to are PS 2.0 - how best to write the scripts to accommodate various/unknown PS versions?

Any assistance would be really appreciated.

Cheers,
Cameron

Offline

#2 21 Oct 2020 13:30

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: PowerShell Remote Execution Question(s)

I always use CALL to run PSEXEC, this won't return an errorlevel, so use a logfile instead.

& $PSExec \\$Server -h -d "C:\install\test-exec.ps1" /log 'C:\logs\test-exec.txt'

If you omit username the remote process will run in the same account from which you execute PsExec, but because the remote process is impersonating it will not have access to network resources on the remote system.

Offline

Board footer

Powered by