Tuesday, 6 January 2009

Using PSExec to Remotely install software

Believe it or not, I got asked what can I use to deploy software, and I said well the list is endless but the question is really are you doing it as a one-off or as a weekly thing?

turns out the guy just wanted to patch some server after finding there was a problem with one HBA card.

So I said what version of windows or Linux he said typically windows, so first thing came to mind Sysinternals tool I love psexec works for me so well I try to use it daily, what I like so much about its that its simple command line no GUI or dependency services.

So for those of you in a lost as to what I'm talking about here its is.
goto microsoft.com or google and type in Sysinternals you'll end up on a TechNet page where the Sysinternals software has been relocated to now since Microsoft took it over, they have some lovely tools but the one I like best is psexec it lets you run remote command like a remote command line.

for /f %i in (c:\serverlist1.txt) do psexec -c -d \\%i Win2003SP3.exe /quiet /norestart /overwriteoem

in this example, the list has just a basic text "serverlist1" with a server on each line or IP the psexec to start the process and then -c says to copy the file to the machine, and -d so it doesn't wait for the program to complete.

another example is the one I use for patching SQL
for /f %i in (c:\list1.txt) do psexec -c -d \\%i c:\SQLSERVER2005SP2-KB921896-x86-ENU.exe /allinstances /quiet

but you can use this with many patches as well example, I created an install.bat file and ran that to deploy many patches to each server the content of the batch file is as follows.

net use X: \\server\share\
@echo off
set PATHTOFIXES=x:\update

%PATHTOFIXES%\WindowsXP-KB######-x86-LLL.exe /quiet /norestart
%PATHTOFIXES%\WindowsXP-KB######-x86-LLL.exe /quiet /norestart
%PATHTOFIXES%\WindowsXP-KB######-x86-LLL.exe /quiet /norestart

net use x: /d

Then I execute this batch file on many servers.
for /f %i in (c:\list1.txt) do psexec -c -d \\%i c:\install.bat

This is how I have install application and service packs on many servers.

I now continue this one my later post. Link


Devon Woods said...

This is great and I can use this. I was wondering if you know how to connect to the remote machine, determine if the OS is 32-bit or 64-bit and then run an install file based on that information?

John Hall said...

as with all things there is more than one way to do it you could use PSINFO tool to get the information or you could look into the registry directly for example x86 is 32bit and AMD64 will be all 64bit unless IA64 but that is not very common these days then take the result to central csv file and you have list for the next command.

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE