Export (0) Print
Expand All

Sample Script for Integrating VMM with OpsMgr

If your network environment includes both System Center Operations Manager and Virtual Machine Manager, you can experiment with the Windows PowerShell script described in this topic to learn how to script Operations Manager discovery of computers that are managed by Virtual Machine Manager.

DiscoverVMMComputers.ps1

Operations Manager can provide end-to-end monitoring of computers that it manages to ensure the health and availability of those computers. For this reason, if your organization has deployed both Operations Manager and Virtual Machine Manager, you should ensure that Operations Manager discovers your Virtual Machine Manager host servers and library servers and incorporates them in the set of computers that is monitored by Operations Manager.

How DiscoverVMMComputers.ps1 Works

The DiscoverVMMComputers.ps1 script performs the tasks described in the following sections.

Connect to the Virtual Machine Manager Server

The first command in DiscoverVMMComputers.ps1 connects to the Virtual Machine Manager server so that subsequent commands can access objects in the Virtual Machine Manager database.

####################################################################
# Connect to the Virtual Machine Manager server
####################################################################
# Substitute the name of your VMM server and domain in this command:
Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

Get All Computers Managed by VMM and Get the Operations Manager Server

Next, the DiscoverVMMComputers.ps1 script gets all the Virtual Machine Manager computers and the Operations Manager server that you want to use to manage those computers:

  • The script uses the VMM cmdlet, Get-VMMManagedComputer, to get the objects that represents all computers managed by Virtual Machine Manager (all virtual machine hosts and all library servers), and stores those computer objects in variable $VMMManagedComputer.
  • The script uses the Operations Manager cmdlet, Get-ManagementServer, to get the object from the Operations Manager database that represents the Operations Manager Management Server, and stores the Management Server object in variable $OpsMgrServer.
####################################################################
# Get all computers managed by VMM and get OpsMgr server
####################################################################
# Get the object for all host and library servers managed by VMM
$VMMManagedComputer = Get-VMMManagedComputer

# Get an instance of the OpsMgr Management Server
$OpsMgrServer = Get-ManagementServer

Add Each VMM-Managed Computer to Operations Manager

Finally, the DiscoverVMMComputers.ps1 script uses a ForLoop to perform the following tasks:

  • Loops through each object in $VMMManagedComputer, in turn.
  • Uses the Operations Manager cmdlet, New-WindowsDiscoveryConfiguration, to create a Windows discovery configuration object for each managed computer and stores the configuration object for each computer in variable $DiscoveryConfig.
    Note
    A Windows discovery configuration object describes a computer so that information about that computer can be discovered by the Start-Discovery cmdlet.

  • Passes the configuration objects that are stored in variable $DiscoveryConfig to the Operations Manager cmdlet, Start-Discovery, which adds the hosts and library servers that are managed by Virtual Machine Manager to the set of computers that is monitored by Operations Manager.
####################################################################
# For each VMM host and library server, initiate a discovery
####################################################################
ForEach ($Computer in $VMMManagedComputer)
{
#Create a new discovery configuration
$DiscoveryConfig = New-WindowsDiscoveryConfiguration -ComputerName $Computer.Name -ComputerType Server

#Initiate the Operations Manager discovery
Start-Discovery -ManagementServer $OpsMgrServer -WindowsDiscoveryConfiguration $DiscoveryConfig
}

DiscoverVMMComputers.ps1 - Complete Script

Copy the following complete version of DiscoverVMMComputers.ps1 into a Notepad file and save it as DiscoverVMMComputers.ps1:

# Filename:    DiscoverVMMComputers.ps1.ps1
# Description: Adds System Center Virtual Machine Manager host servers 
#              and library servers to the set of computers managed 
#              by System Center Operations Manager.

# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This 
# script is made available to you without any express, implied or 
# statutory warranty, not even the implied warranty of 
# merchantability or fitness for a particular purpose, or the 
# warranty of title or non-infringement. The entire risk of the 
# use or the results from the use of this script remains with you.

####################################################################
# Connect to the Virtual Machine Manager server
####################################################################
# Substitute the name of your VMM server and domain in this command:
Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

####################################################################
# Get all computers managed by VMM and get OpsMgr server
####################################################################
# Get the object for all host and library servers managed by VMM
$VMMManagedComputer = Get-VMMManagedComputer

# Get an instance of the OpsMgr Management Server
$OpsMgrServer = Get-ManagementServer

####################################################################
# For each VMM host and library server, initiate a discovery
####################################################################
ForEach ($Computer in $VMMManagedComputer)
{
#Create a new discovery configuration
$DiscoveryConfig = New-WindowsDiscoveryConfiguration -ComputerName $Computer.Name -ComputerType Server

#Initiate the Operations Manager discovery
Start-Discovery -ManagementServer $OpsMgrServer -WindowsDiscoveryConfiguration $DiscoveryConfig
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft