My test environment usually has a dozen or so machines at any one time. Some of these are short lived and used for a particular piece of testing – others are kept for years. I decided that I wanted to keep up to date on the patching of these virtual machines so installed WSUS on a Windows 2012 box.
One issue is that if a VM isn’t started for 10 days WSUS starts complaining that it hasn’t been contacted and if you run the WSUS clean up wizard the non-reporting servers may be removed. Checking the WSUS console for which machines haven’t sync’d recently is a chore.
In Windows 2012 both WSUS and Hyper-V come with a PowerShell module. This means I can do this:
1 2 3 4 5 6 7 8 |
<span style="color:#ff4500;">$date</span> <span style="color:#a9a9a9;">=</span> <span style="color:#000000;">(</span><span style="color:#0000ff;">Get-Date</span><span style="color:#000000;">)</span><span style="color:#a9a9a9;">.</span><span style="color:#000000;">AddDays</span><span style="color:#000000;">(</span><span style="color:#800080;">-10</span><span style="color:#000000;">)</span> <span style="color:#0000ff;">Get-WsusComputer</span> <span style="color:#000080;">-ToLastSyncTime</span> <span style="color:#ff4500;">$date</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">sort</span> <span style="color:#8a2be2;">LastSyncTime</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">select</span> <span style="color:#000080;">-First</span> <span style="color:#800080;">4</span> <span style="color:#a9a9a9;">|</span> <span style="color:#0000ff;">foreach</span> <span style="color:#000000;">{</span> <span style="color:#ff4500;">$computer</span> <span style="color:#a9a9a9;">=</span> <span style="color:#000000;">(</span><span style="color:#ff4500;">$_</span><span style="color:#a9a9a9;">.</span><span style="color:#000000;">FullDomainName</span> <span style="color:#a9a9a9;">-split</span> <span style="color:#8b0000;">"\."</span><span style="color:#000000;">)</span><span style="color:#a9a9a9;">[</span><span style="color:#800080;">0</span><span style="color:#a9a9a9;">]</span> <span style="color:#0000ff;">Start-VM</span> <span style="color:#000080;">-Name</span> <span style="color:#ff4500;">$computer</span> <span style="color:#000080;">-ComputerName</span> <span style="color:#8a2be2;">Server02</span> <span style="color:#000080;">-Passthru</span> <span style="color:#000000;">}</span> |
I’m using the WSUS server as my admin box but if you were accessing a remote WSUS machine change the code to
Get-WsusServer -Name w12sus -PortNumber 8530 | Get-WsusComputer –ToLastSyncTime $date |
I sorted the computers WSUS knows about by date – picked the last 4 to sync so I didn’t overwhelm the Hyper-V host and started them up. Only trick is to get the computer name out of the FullDomainName property.