Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there any batch script or command line command that can do Windows Update automatically on multiple remote servers (maybe via psexec)? Not prefer using a VB script, but if there's one available, that's fine too. Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Depends on how you want to do. If you want a more batch-style, psexec method, you need to look into a shareware CLI utility I have seen before. To be honest, I have never tested it myself, wuinstall. I see some articles from Windows-type IT mags, so I doubt you will be the first guy. There is a freeware and pro version, but I cannot say what the licensing restrictions are.

If you can get over the scripting, I know this Winboxen sysadmin lucifist wrote a PowerShell script to do what you are looking for.

######################################################################################################################################
# Windows Update through Powershell (No Forms) v1.0 ######################################################################################################################################
clear-host
Write-host "Starting Update Process..." -foregroundcolor blue
Write-host ""
$UpdateSession = New-Object -com Microsoft.Update.Session 
$UpdateSearcher = $UpdateSession.CreateupdateSearcher() 
$SearchResult =  $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")
$UpdateLowNumber = 0 
$UpdateHighNumber = 1 
$NumberofUpdates = $searchResult.Updates.Count


while ($UpdateHighNumber -le $NumberofUpdates) {
$UpdatesToDownload = New-Object -com Microsoft.Update.UpdateColl 
$Update = $searchResult.Updates.Item($UpdateLowNumber) 


if ($Update.EulaAccepted -eq 0) {$Update.AcceptEula()} 


[void]$UpdatesToDownload.Add($Update)
$Downloader = $UpdateSession.CreateUpdateDownloader() 
$Downloader.Updates = $UpdatesToDownload 
[void]$Downloader.Download()


$UpdatesToInstall = New-Object -com Microsoft.Update.UpdateColl 
[void]$UpdatesToInstall.Add($Update)


$Title = $update.Title 
$KBArticleIDs = $update.KBArticleIDs
$SecurityBulletinIDs = $update.SecurityBulletinIDs
$MsrcSeverity = $update.MsrcSeverity
$LastDeploymentChangeTime = $update.LastDeploymentChangeTime
$MoreInfoUrls = $update.MoreInfoUrls


Write-host "Installing Update $UpdateHighNumber of $NumberofUpdates"
Write-host "Title: $Title"
if ($KBArticleIDs -ne "") {Write-host "KBID: $KBArticleIDs"}
if ($SecurityBulletinIDs -ne "") {write-host "Security Bulletin: $SecurityBulletinIDs"}
if ($MsrcSeverity -eq "Critical") {Write-host "Rating: $MsrcSeverity" -foregroundcolor red} else {Write-host "Rating: $MsrcSeverity"}
if ($LastDeploymentChangeTime -ne "") {Write-host "Dated: $LastDeploymentChangeTime"}
if ($MoreInfoUrls -ne "") {Write-host "$MoreInfoUrls"}


$Installer = $UpdateSession.CreateUpdateInstaller() 
$Installer.Updates = $UpdatesToInstall 
$InstallationResult = $Installer.Install()
Write-host "--------------------------------------------"
if ($InstallationResult.ResultCode -eq "2") {Write-host "  Installation Succeeded" -foregroundcolor green}  else {Write-host "  INSTALLATION FAILED, check event log for details" -foregroundcolor red}
if ($InstallationResult.RebootRequired -eq "False") {Write-host "  Reboot not required" -foregroundcolor green} else {Write-host "  REBOOT REQUIRED" -foregroundcolor red}
Write-host "--------------------------------------------"
Write-host ""
Write-host ""


$Title = ""
$KBArticleIDs =  ""
$SecurityBulletinIDs =  ""
$MsrcSeverity =  ""
$LastDeploymentChangeTime =  ""
$MoreInfoUrls =  ""


$UpdateLowNumber = $UpdateLowNumber + 1 
$UpdateHighNumber = $UpdateHighNumber + 1


if ($ProgressValue -lt $NumberofUpdates) {$ProgressValue = $ProgressValue + 1} 
} 


$ComputerStatus = New-Object -com Microsoft.Update.SystemInfo
 if ($ComputerStatus.RebootRequired -eq 1) {cmd /c $env:WinDir\System32\Shutdown.exe -r -f -t 10 -c "Patching Complete."}

If you pay attention to this script, you will see you are opening up COM objects and such. So, you either need to bake your own binary or someone else's non-MSFT code (a la Wuinstall), or do the same amount of scripting in VBScript. You say Win23k Server, so I am not sure whether or not you have PS installed. If not, there is TechNet documentation to cure your ills.

Bottom line, Google is your friend. Keep that in mind before posting here. :-)

share|improve this answer
2  
Posting questions here makes Google a better friend for other people later on. There are no bad questions, per se. –  Evan Anderson Jul 20 '10 at 21:24
    
Oh, totally agree. I was just pointing out that I had found all of this on Google. And to be fair, knowing the exact phrase to use is more important than knowing its omnipotence. :-) –  ajstein Jul 21 '10 at 7:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.