Starting VMs based on WSUS state

I use WSUS in my lab to update machines – means I only have to download updates once. The issue is that I have to start the VMs so they can communicate with the WSUS server. WSUS will start to flag warnings if machines haven’t contacted the WSUS server for more than that length of time.

Putting that together I can use the UpdateServices (WSUS) module and the Hyper-V module to start machines that have been turn off more than 7 days.

$date = (Get-Date).AddDays(-7)
Get-WsusComputer -NameIncludes ‘W12R2’ |
where LastReportedStatusTime -lt $date |
foreach {
  $name = ($psitem.FullDomainName -split “\.”)[0]

  $vm = Get-VM -Name $name -ComputerName server02
  if ($vm.State -eq ‘Off’) {

    Start-VM -Name $name -ComputerName server02
    Start-Sleep -Seconds 30

Set a date 7 days in the past.

Use get-WsusComputer to pull the machine names. I filter on W12R2 (all my machine names contain an abbreviated OS type) and check the last status report time.

Any machines that haven’t reported – the VM data is retrieved and if the machine isn’t running it’s started. Machines take about 25-30 seconds to boot on my lab so a sleep of 30 seconds means I’m not starting them all at once.

This entry was posted in Hyper-V, Powershell, WSUS. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s