Using VMM Cmdlets locally on SMA Worker Server in SMA Runbooks

If you are working with SMA and VMM you are probably familiar with the following sample Runbook for connecting to VMM:

workflow Sample-Managing-VirtualMachineManager  {      # Connection to access VMM server.      $VmmConnection = Get-AutomationConnection -Name 'VmmConnection'      $VmmServerName = $VmmConnection.ComputerName        # Create a PSCredential from the 'Username' and 'Password' fields within       # 'VmmConnection' because this is the form of authentication that an       # inlinescript accepts.       $SecurePassword = ConvertTo-SecureString -AsPlainText -String $VmmConnection.Password -Force      $VmmCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $VmmConnection.Username, $SecurePassword            inlinescript {          # Import VMM module.          Import-Module virtualmachinemanager                    # Connect to VMM server.          Get-SCVMMServer -ComputerName $Using:VmmServerName            # Obtain VMM server license information.          Get-SCVMMAccessLicense -VMMServer $Using:VmmServerName -License      } -PSComputerName $VmmServerName -PSCredential $VmmCredential  }
Trough this way basically you are making remote connection to the VMM server and you are executing everything there. For most cases this is not the best way and there is another one. The other way is to install the VMM console on the SMA worker server/s thus making available the VMM cmdlets there. Keep in min that this also requires updating the console upon new Update rollup.
Now that we have the cmdlets on the SMA worker you can use a simple example like this to make the connection to VMM:

workflow Get-VM

$VmmConnection = Get-AutomationConnection -Name ‘VmmConnection’
$VmmServerName = $VmmConnection.ComputerName
$SecurePassword = ConvertTo-SecureString -AsPlainText -String $VmmConnection.Password -Force
$VmmCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $VmmConnection.Username, $SecurePassword
$VMMobject=Get-SCVMMServer -ComputerName $VmmServerName -Credential $VmmCredential

$VMS=Get-SCVirtualMachine -VMMServer $VmmServerName | select -Property Name


Hope this helps you when you integrate SMA and VMM.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.