Installing pathes/Application on a remote computer is not a tough one when you have lots of Microsoft and third party application to do this for us.Chances that few companies still does not wanted to relay on software to install patches and Administrator manually installed this. You should ask this question to the Administrators who works on weekend installing patches manually, do you like this to do every weekend ? I am sure he will give you very dirty look for sure 🙂
Below is the small piece of code you may like to use it for installing pathces or any small application on various computer remotely.
Prerequisits
1. Download PSExec.exe from Microsoft.com (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) and copy to C:\Psexec.exe
2. Create C:\Hotfixes and dump the path here
3. Copy below code and save it as C:\patchinstall.vbs
4. Create C:\Servers.txt with list of servername
5. Rename with the appropriate name
6. Open command prompt type cscript C:\patchinstall.vbs
This code will copy the patch to all the remote computer mentioned in C:\Servers.txt under C:\Hotfixes and it uses psexec.exe to install the patch on the remote computer
Set objShell = CreateObject("Wscript.Shell")Set objFSO = CreateObject("Scripting.FileSystemObject") set filetxt = objFSO.OpenTextFile("C:\Servers.txt",1)strPSExec = "C:\PSExec.exe"rbcopy = "c:\Windows\System32\Robocopy.exe"strPSExec = objFSO.GetFile(strPSExec).ShortPathrbcopy = objFSO.GetFile(rbcopy).ShortPath do Until filetxt.AtEndOfStream strComputer = filetxt.Readline strComputer = trim(strComputer) strCmd = "cmd /C " & rbcopy & " C:\Hotfixes" & " \\" & strComputer & "\c$\Hotfixes" wscript.echo strcmd objShell.Run strCmd, 1, True strCmd = "cmd /C " & strPSExec & " \\" & strComputer & " ""C:\Hotfixes\<Hotfixname.exe>"" /quite" wscript.echo strcmd objShell.Run strCmd, 1, TrueLoop
Nice one Krishna! that is one good idea for small companies cant get better
Hey Thanks Vijay..
Regards,
Krishna
Additional solution, that I’ve built years ago for myself. I called it “Free Deployment System” 🙂
http://www.curuit.com/free-deployment-system-2007111465/
This is great Misha..
Thank you very much.
Regards,
Krishna
I am trying to run this script from xp i m getting error on line 9 ,
While ago i did something similar for myself :).
You can read about my solution here: http://www.curuit.com/free-deployment-system-2007111465/
it is pure Batch 🙂
Its not working for me. It do copy the files in the specified directory on remote machine but nothing else. I cant see patch applied to the machine in window update history.
I really need this solution as i have to deploy many patches manually as WSUS is not doing the work.
Please help
hi!
its not working for me. it just copies the data and do nothing. I guess it searches for hotfix.exe file.
you need to keep hotfix in location C:\Hotfixes
Hi Krishna!
Thanks for the reply. Yes the hotfix are in C:\Hotfixes both on source and destination computers.
Its works fine with copying but it cant execute the file.
What version of Windows do you have on a destination computer?
Its window 7 Enterprise.
I think the problem is here:
“”C:\Hotfixes\”” /quite” . It cant find .
I guess there is something else instead of
I entered file name direct:
strCmd = “cmd /C ” & strPSExec & ” \\” & strComputer & ” “”C:\Hotfixes\SQLServer2008R2-KB2494088-x64.exe”” /quite”
but even that didnt help. I can see in a flash screen that its says
The system cannot find the specified file.
try to change cmd /c to CMD / K
By doing this, the CMD console will stay opened, so maybe you will see more details.
i think its a psexec problem but not sure. any suggestions?
ok finally i manage to run it with manual way i.e inserting the file name instead of . The script copies the file and run for more than 1 min and i can see some message in new command prompt in a flash and thats it. I cant find the KB installed on the remote computer.
Any way i can print the error message on the screen or file?
Just stuck after copying. Is it because its a Sqlserver hotfix?
I have also ran into the issue with the /accepteula since it requires user acceptance on psexec.exe
You must edit the line in the script: “”C:\Hotfixes\””
Change into your patch file name eg. “”C:\Hotfixes\KB999999.exe””
Also, there’s a typo in the script. /quite must be fixed to /quiet
how would I install a list of patches from a folder that contains more than 20 patches to machines that few will need 5 patches other 8 and the rest 20 patches…. any input on this one… this is my dilemma that I have…. please help
There’s an app called Batchpatch that lets you automate this process. The free evaluation is good for up to 7 remote hosts at a time. Check it here: http://batchpatch.com
Hi Krishna,
i would want to install the patch but not to reboot the server, any additional lines should be added to the script?
Thank You
I want to get a report in which machines the patch is installed. Is there any way how to get that and include in the script
Hi Madhu,
Refer below link & u can generate report for multiple computers / server on one KB# / Hotfix #
https://gallery.technet.microsoft.com/scriptcenter/Generate-a-Report-for-f71a6800
copy & save below code in notepad & rename to anyname.ps1 grant full permission to yourself & try your luck
computers.txt – mention the name of the servers
$computers = cat c:\computers.txt
$Patch = “KB2819745”
foreach ($computer in $computers)
{
if (get-hotfix -id $Patch -ComputerName $computer -ErrorAction 2)
{
Add-content “Hotfix is Present in $computer” -path “$env:USERPROFILE\Desktop\Hotfix-Present.log”
}
Else
{
Add-content “Hotfix is not Present in $computer” -path “$env:USERPROFILE\Desktop\Missing-Hotfix.log”
}
}
Hi Everyone!
It does not work for me. I have error on Line 8, Char 1.
This is what I have:
Set objShell = CreateObject(“Wscript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
set filetxt = objFSO.OpenTextFile(“D:\Equipos.txt”,1)
strPSExec = “D:\PSExec.exe”
rbcopy = “c:\Windows\System32\Robocopy.exe”
strPSExec = objFSO.GetFile(strPSExec).ShortPath
rbcopy = objFSO.GetFile(rbcopy).ShortPath
do Until filetxt.AtEndOfStream
strComputer = filetxt.Readline
strComputer = trim(strComputer)
strCmd = “cmd /C ” & rbcopy & ” D:\Hotfixes\kb4012212_x86.msu” & ” \\” & strComputer & “\D$\Hotfixes\kb4012212_x86.msu”
wscript.echo strcmd
objShell.Run strCmd, 1, True
strCmd = “cmd /C ” & strPSExec & ” \\” & strComputer & ” “”D:\Hotfixes\”” /quiet”
wscript.echo strcmd
objShell.Run strCmd, 1, True
Loop