Sashkin - Fotolia


Address bulk VMM agent updates with PowerShell automation

The SCVMM agent upgrade process is a regular, but sometimes laborious, part of VM management. Use PowerShell to make light work of bulk updates through commands and loops.

Periodically, admins need to update every VMM agent on their managed servers with System Center Virtual Machine Manager. Although the System Center Virtual Machine Manager console provides a mechanism for VMM agent updates, it's not well-suited to bulk agent management. With PowerShell cmdlets, you can efficiently update agents on a larger scale.

Identify servers that need an update

Use Get-VMMManagedComputer, one of the commands available in the System Center Virtual Machine Manager (SCVMM) command shell, to return information about managed virtualization hosts and SCVMM library servers. Although this tool has many purposes, its relevant function here is to identify the managed servers for which a VMM agent update exists.

To get an idea of the types of information that this cmdlet returns, enter the following command:

Get-VMMManagedComputer <the name of one of your managed servers> | Select-Object *

Information about managed servers
Figure A. This cmdlet returns information about the managed computer.

Notice that one of the items is named VersionStateString. This string reflects the agent status. In this case, a VMM agent upgrade is available.

Find statuses for all the managed systems

Use a variation of this technique to display the agent statuses for all the managed systems. If you want to view the computer name and the agent statuses for all your managed computers, for example, use the following command:

Get-VMMManagedComputer | Select-Object ComputerName, VersionStateString

This command shows you which managed computers have up-to-date VMM agents and which require updates. 

Managed systems and their agent statuses
Figure B. This cmdlet returns a list of all the managed systems and their agent statuses.

Use PowerShell to enable bulk updates

To update VMM agents in bulk, you need to first identify which managed systems have agents that can be upgraded. We can accomplish this with simple PowerShell filtering. This is an example of a command that you could use:

Get-VMMManagedComputer | Where {$_.VersionStateString -EQ "Upgrade Available"} | Select-Object ComputerName, VersionStateString

This command checks the VersionStateString to see if it is equal to Upgrade Available. As you can see, the results now include only managed systems for which a VMM agent update is available.

Results that only show managed systems with available updates
Figure C. Filter the output by the version state string.

Before you use this information to update the agents, you need to capture credentials for the VMM agent upgrade process. The easiest way to do this is to capture a set of administrative credentials and assign them to a variable. Here is an example:

$Cred = Get-Credential

This creates a variable named $Cred that contains the credentials you provide.

You'll also need another variable that will contain a list of the managed computers that need to be updated. For that, tie a variable name to the Get-VMMManagedComputer command used earlier. For the sake of the example, let's name the variable $Servers.

$Servers = Get-VMMManagedComputer | Where {$_.VersionStateString -EQ "Upgrade Available"}

Once you assign the necessary variables, we can use a simple loop to perform the update.

ForEach ($Server in $Servers) { Update-VMMManagedComputer $Server -Credential $Cred}

Notice that the Update-VMMManagedComputer cmdlet performs the actual agent update. The $Cred variable supplies the necessary credentials to this cmdlet and the $Server variable supplies the server name. You can use the Get-VMMManagedComputer cmdlet to confirm that the update was successful.

An updated agent
Figure D. The agent is now updated.

Although the GUI arguably provides an easier interface for VMM agent updates, it doesn't scale well. If you need to update multiple servers' agents, then PowerShell is your best option.

Dig Deeper on Containers and virtualization

Software Quality
App Architecture
Cloud Computing
Data Center