MS Windows Remote Installs

Use this script to run a program remotely. In this scenario the script is used to install IE9 onto a remote MS Windows 7 machine.

PSTools Download Link

How to use:

Save the below script as a ‘.bat’ file.
Update the script to reflect the network share where the IE9 (or other) install / upgrade package is stored.

On running the script you will be shown a CMD box asking for an asset tag (also known as hostname). Enter the PC asset tag, select Enter… The Script will connect to the remote computer, copy the installation file over to a C:\temp folder, run the installer using the switches provided and the delete the file once completed.

The script should return an ‘error’ code of 0, this means the installation completed with no issues.

 

@echo off
REM *********************************************
REM A.Nicholls
REM http://www.adienicholls.co.uk/blogs
REM 25/05/2016
REM *********************************************

REM Get remote PCs hostname
set /p id=Enter Hostname:

REM Copy the install file from source to destination PC
robocopy \\Server\shared\ms\ie9 \\%id%\c$\temp\ *.exe /r:0 /w:0

REM executes the copied file through CMD
psexec \\%id% cmd.exe /c "c:\temp\IE9-Windows7-x86-enu.exe" /quiet /closeprograms /update-no /norestart

REM verifying return codes
ECHO ________________________________________________________________
ECHO (1)     Error, opps something went wrong
ECHO (0)     Installation Succeeded
ECHO ________________________________________________________________

REM Cleanup - Delete the previously copied file
psexec \\%id% cmd.exe /c DEL "c:\temp\IE9-Windows7-x86-enu.exe" /q

REM providing a cleaner exit code for the file deletion
if ERRORLEVEL 1 echo *****OOPS, couldnt remove the file*****
if ERRORLEVEL 0 echo cleanup completed

pause

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.