An ongoing project here at work is server maintenance and applying patches. One of the issue we’ve been facing is how to do windows updates for clusters. While we could do an AD structure and schedule different install and restart times for the different sides, we can’t include checks to see if the other side of the cluster is up.
So now, we’re working on a set of tools that can initiate Windows Updates, check if other servers are up or down, and then restart accordingly. Thus far, I’ve just finished this script, the rest of the tool will likely be done with C# and set as a service on each machine. With this script, you can check the updates for other machines from the comfort of your desktop/laptop and send it off to a text file for later viewing. You can even initiate the update process! Albeit, only on the machine you’re running on due to constraints of the Microsoft.Update.Session COM.
param (
$computer = $env:computername,
[switch]$searchOnly
)
[Reflection.Assembly]::LoadFrom("C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Microsoft.VisualBasic.dll") | out-null;
#Create an update session
#Using the vb createObject method, we are able to connect to remote machines to view
#it's update list
$updateSession = [microsoft.visualbasic.interaction]::CreateObject("Microsoft.Update.Session", $computer);
"Finding updates on $($computer)"
$updateSearch = $updateSession.CreateUpdateSearcher()
#Here we're only wanting to know what it needs and what it has been assigned.
#IsAssigned should really only apply to networks that utilize WSUS.
$results = $updateSearch.Search('IsInstalled=0 and IsAssigned=1')
if($searchOnly.IsPresent -or $computer -ne $env:computername) {
$results.Updates
} else {
"Downloading updates"
$updateDownload = $updateSession.CreateUpdateDownloader()
$updateDownload.Updates =$results.Updates
$updateDownload.Download()
"Installing updates"
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $updateDownload.Updates
$installer.install()
}


[...] Finding applicable Windows Updates via cli This entry was written by josh, posted on October 8, 2009 at 2:31 pm, filed under code, csharp, dotnet and tagged BeginInstall, CreateUpdateSearcher, UpdateSessionClass, Windows Update, WSUS, WUApi. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL. « Fixed: fastping, now with working get-help comments [...]