Export (0) Print
Expand All

Sample Script Summarizing VMM Information

You can experiment with the Windows PowerShell script SummarizeVMMInformation.ps1 to learn how to display a summary of information about your Virtual Machine Manager environment. This script demonstrates how to display a variety of information about the Virtual Machine Manager server, host and library servers, host groups, virtual machines, and self-service policies.

SummarizeVMMInformation.ps1

The following sections describe each set of commands that make up the SummarizeVMMInformation.ps1 script.

Display Information About the Virtual Machine Manager Server

The first set of commands in SummarizeVMMInformation.ps1 performs the following tasks:

  1. Retrieves today's date from the system and stores the date in variable $SummaryDate.
  2. Connects to the Virtual Machine Manager server, VMMServer1, in the Contoso.com domain, retrieves the server object from the Virtual Machine Manager database, and stores the server object in variable $VMMServer.
  3. Retrieves, from the Virtual Machine Manager database, the Virtual Machine Manager host objects as an array and stores the host objects in variable $VMHosts.
  4. Retrieves, from the Virtual Machine Manager database, all virtual machine objects and uses the pipeline operator (|) and where statement to select only objects for virtual machines that are not stored in the library. The command stores these virtual machine objects in variable $HostedVMs.
  5. Displays the following summary information about your Virtual Machine Manager server and its hosts and virtual machines:
    • Today's date.
    • The name of the Virtual Machine Manager server.
    • Whether this is an evaluation version of the Virtual Machine Manager software.
    • The placement goal (the two possible values are LoadBalance or Consolidate) that Virtual Machine Manager uses to select the most suitable host on which to deploy a virtual machine. LoadBalance refers to load balancing among hosts, which minimizes the processing load on any one host. Consolidate refers to resource maximization on individual hosts, which consolidates multiple low-utilization workloads on a single host.
    • The number of hosts added to this Virtual Machine Manager server.
    • The number of virtual machines deployed on any host.
    • The average number of virtual machines per host.
####################################################################
# Summary of Virtual Machine Manager Server
####################################################################
$SummaryDate = Get-Date
# Substitute the name of your VMM server and domain in this command:
$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"
$VMHosts = @(Get-VMHost)
$HostedVMs = @(Get-VM | where {$_.Status -ne "Stored"})

Write-Host "`nVIRTUAL MACHINE MANAGER SERVER" -ForegroundColor Yellow

Write-Host "Summary Date       :", $SummaryDate
Write-Host "VMM Server Name    :", $VMMServer.Name
Write-Host "Evaluation Version :", $VMMServer.IsEvaluationVersion
Write-Host "Placement Goal     :", $VMMServer.PlacementGoal
Write-Host "Total Hosts        :", $VMHosts.Count
Write-Host "Hosted VMs         :", $HostedVMs.Count
if ($VMHosts.Count -ne 0)
{
Write-Host "VMs per Host       :", ($HostedVMs.Count / $VMHosts.Count)
}

Display Information About Host Servers

The next set of commands performs the following tasks:

  1. Retrieves, from the Virtual Machine Manager database, all Virtual Machine Manager host objects as an array and stores the host objects in variable $VMHosts.
  2. Displays the following summary information about your virtual machine hosts, using the pipeline operator (|) and where statement to filter host objects based on specific criteria:
    • The total number of hosts.
    • The number of hosts that are not responding.
    • The total number of hosts on which you need to install an updated version of the Virtual Machine Manager agent software.
    • The total number of hosts on which you need to install an updated version of the Microsoft Virtual Server 2005 software.
    • The number of hosts that are categorized as maintenance hosts. A maintenance host is a host that you can dedicate for patching stored resources and for staging virtual machines before you move them into your production environment.
    • The number of hosts that are located in a perimeter network.
####################################################################
# Summary of Virtual Machine Hosts
####################################################################
$VMHosts = @(Get-VMHost)

Write-Host "`nVIRTUAL MACHINE HOSTS" -ForegroundColor Yellow

Write-Host "Total Hosts                             :", $VMHosts.Count
Write-Host "Hosts Not Responding                    :", @($VMHosts | where {$_.Status -eq "NotResponding"}).Count
Write-Host "Hosts Needing Agent Update              :", @($VMHosts | where {$_.Agent.VersionState -eq "NeedsUpdate"}).Count
Write-Host "Hosts Needing Virtual Server Update     :", @($VMHosts | where {$_.VirtualServerVersionState -eq "NeedsUpdate"}).Count
Write-Host "Hosts in Maintenance                    :", @($VMHosts | where {$_.MaintenanceHost -eq $true}).Count
Write-Host "Hosts on Perimeter Network              :", @($VMHosts | where {$_.PerimeterNetworkHost -eq $true}).Count

Display Information About Virtual Machines

The next set of commands performs the following tasks:

  1. Retrieves, from the Virtual Machine Manager database, all virtual machine objects as an array and stores the virtual machine objects in variable $VMs.
  2. Displays the following summary information about your virtual machines, using the pipeline operator (|) and where statement to filter virtual machine objects based on specific criteria:
    • The total number of virtual machines.
    • The number of virtual machines that are currently deployed on host servers.
    • The number of virtual machines that are currently stored in the Virtual Machine Manager library.
    • The number of virtual machines that are currently running.
    • The number of virtual machines that are currently available for self-service users.
    • The number of virtual machines on which Virtual Manager Additions is not installed.
####################################################################
# Summary of Virtual Machines
####################################################################
$VMs = @(Get-VM)

Write-Host "`nVIRTUAL MACHINES" -ForegroundColor Yellow

Write-Host "Total VMs    :", $VMs.Count
Write-Host "Hosted VMs   :", @($VMs | where {$_.Status -ne "Stored"}).Count
Write-Host "Stored VMs   :", @($VMs | where {$_.Status -eq "Stored"}).Count
Write-Host "Running VMs  :", @($VMs | where {$_.Status -eq "Running"}).Count
Write-Host "Self-Service VMs           :", @($VMs | where {$_.SelfServicePolicy -ne $null}).Count
Write-Host "VMs without VMAdditions    :", @($VMs | where {$_.HasVMAdditions -eq $false}).Count

Display Information About Self-Service Policies

The next set of commands performs the following tasks:

  1. Retrieves, from the Virtual Machine Manager database, self-service policy objects as an array and stores the policy objects in variable $SelfServicePolicies. A self-service policy allows a user or members of a group to create and manage their own virtual machines through the Virtual Machine Manager self-service feature. Self-service users manage their virtual machines through a Web site called the Self-Service Portal.
  2. Displays the following summary information about virtual machines that are available to self-service users, using the pipeline operator (|) and where statement to filter virtual machine objects based on specific criteria:
    • The total number of self-service policies.
    • The total number of virtual machines that are available for self-service users.
    • The number of virtual machines that are assigned to self-service users and are currently deployed on a host server.
    • The total number of virtual machines that are assigned to self-service users and that are currently stored in the Virtual Machine Manager library. These virtual machines are unavailable to self-service users unless the self-service policy that governs these machines includes the permission that allows users to store their virtual machines in the library. The store permission also enables users to deploy a stored virtual machine on a host server (unless the quota-points setting blocks the deployment of additional virtual machines).
####################################################################
# Summary of Self-Service
####################################################################$Se$SelfServicePolicies = @(Get-SelfServicePolicy)
$VMs = @(Get-VM)

Write-Host "`nSELF-SERVICE" -ForegroundColor Yellow

Write-Host "Self Service Policies   :", $SelfServicePolicies.Count
Write-Host "Total Self-Service VMs  :", @($VMs | where {$_.SelfServicePolicy -ne $null}).Count
Write-Host "Hosted Self-Service VMs :", @($VMs | where {$_.SelfServicePolicy -ne $null} | where {$_.Status -ne "Stored"}).Count
Write-Host "Stored Self-Service VMs :", @($VMs | where {$_.SelfServicePolicy -ne $null} | where {$_.Status -eq "Stored"}).Count

Display Information About Library Servers

The next set of commands in SummarizeVMMInformation.ps1 performs the following tasks:

  1. Retrieves, from the Virtual Machine Manager database, all library server objects and stores the library server objects in variable $LibraryServers.
  2. Retrieves, from the Virtual Machine Manager database, all virtual machine objects as an array and stores the virtual machine objects in variable $VMs.
  3. Displays the number of library servers and the number of virtual machines that are stored in the Virtual Machine Manager library.
####################################################################
# Summary of Library Servers
####################################################################
$LibraryServers = @(Get-LibraryServer)
$VMs = @(Get-VM)

Write-Host "`nLIBRARY SERVERS" -ForegroundColor Yellow

Write-Host "Library Servers :", $LibraryServers.Count
Write-Host "Stored VMs      :", ($VMs | where {$_.Status -eq "Stored"}).Count

Display Information About Host Groups

The final set of commands in SummarizeVMMInformation.ps1 performs the following tasks:

  1. Retrieves, from the Virtual Machine Manager database, all virtual machine host groups as an array and stores the host group objects in variable $VMHostGroups.
  2. Retrieves, from the Virtual Machine Manager database, all virtual machine objects as an array and stores the virtual machine objects in variable $VMs.
  3. For each host group, determines the following:
    • The number of hosts in the host group.
    • The number of virtual machines in the host group.
    • The number of running virtual machines on hosts in the host group.
    • The number of virtual machines that are allocated to self-service users in the host group.
  4. Displays the following information about each host group:
    • The name of the host group.
    • The number of hosts in the host group.
    • The number of virtual machines, running virtual machines, and self-service virtual machines in the host group.
    • The number of virtual machines on each host ($VMCount / $VMHostCount); the number of running virtual machines on each host ($RunningVMCount / $VMHostCount), and the number of self-service virtual machines on each host ($SelfServiceVMCount / $VMHostCount).
####################################################################
# Summary of Virtual Machine Host Groups
####################################################################
$VMHostGroups = @(Get-VMHostGroup)
$VMs = @(Get-VM)

Write-Host "`nVIRTUAL MACHINE HOST GROUPS" -ForegroundColor Yellow

foreach ($VMHostGroup in $VMHostGroups)
{
    $VMHostCount = $VMHostGroup.Hosts.Count
    $VMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost}).Count
    $RunningVMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost} | where {$_.Status -eq "Running"}).Count
    $SelfServiceVMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost} | where {$_.SelfServicePolicy -ne $null}).Count

    Write-Host "Host Group               :", $VMHostGroup.Name
    Write-Host "Number of Hosts          :", $VMHostCount
    if ($VMHostCount -ne 0)
    {
    Write-Host "Number of VMS            :", $VMCount
    Write-Host "Running VMs              :", $RunningVMCount
    Write-Host "Self-Service VMs         :", $SelfServiceVMCount
    Write-Host "VMs per Host             :", ($VMCount / $VMHostCount)
    Write-Host "Running VMs per Host     :", ($RunningVMCount / $VMHostCount)
    Write-Host "Self-Serice VMs per Host :", ($SelfServiceVMCount / $VMHostCount)
    }
    Write-Host
}

SummarizeVMMInformation.ps1 - Complete Script

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

# Filename:    SummarizeVMMInformation.ps1
# Description: Display information about Virtual Machine Manager 
#              servers (including hosts and library servers), 
#              host groups, virtual machines, and self-service 
#              policies.

# 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.

####################################################################
# Summary of Virtual Machine Manager Server
####################################################################
$SummaryDate = Get-Date
# Substitute the name of your VMM server and domain in this command:
$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"
$VMHosts = @(Get-VMHost)
$HostedVMs = @(Get-VM | where {$_.Status -ne "Stored"})

Write-Host "`nVIRTUAL MACHINE MANAGER SERVER" -ForegroundColor Yellow

Write-Host "Summary Date       :", $SummaryDate
Write-Host "VMM Server Name    :", $VMMServer.Name
Write-Host "Evaluation Version :", $VMMServer.IsEvaluationVersion
Write-Host "Placement Goal     :", $VMMServer.PlacementGoal
Write-Host "Total Hosts        :", $VMHosts.Count
Write-Host "Hosted VMs         :", $HostedVMs.Count
if ($VMHosts.Count -ne 0)
{
Write-Host "VMs per Host       :", ($HostedVMs.Count / $VMHosts.Count)
}

####################################################################
# Summary of Virtual Machine Hosts
####################################################################
$VMHosts = @(Get-VMHost)

Write-Host "`nVIRTUAL MACHINE HOSTS" -ForegroundColor Yellow

Write-Host "Total Hosts                             :", $VMHosts.Count
Write-Host "Hosts Not Responding                    :", @($VMHosts | where {$_.Status -eq "NotResponding"}).Count
Write-Host "Hosts Needing Agent Update              :", @($VMHosts | where {$_.Agent.VersionState -eq "NeedsUpdate"}).Count
Write-Host "Hosts Needing Virtual Server Update     :", @($VMHosts | where {$_.VirtualServerVersionState -eq "NeedsUpdate"}).Count
Write-Host "Hosts in Maintenance                    :", @($VMHosts | where {$_.MaintenanceHost -eq $true}).Count
Write-Host "Hosts on Perimeter Network              :", @($VMHosts | where {$_.PerimeterNetworkHost -eq $true}).Count

####################################################################
# Summary of Virtual Machines
####################################################################
$VMs = @(Get-VM)

Write-Host "`nVIRTUAL MACHINES" -ForegroundColor Yellow

Write-Host "Total VMs                :", $VMs.Count
Write-Host "Hosted VMs               :", @($VMs | where {$_.Status -ne "Stored"}).Count
Write-Host "Stored VMs               :", @($VMs | where {$_.Status -eq "Stored"}).Count
Write-Host "Running VMs              :", @($VMs | where {$_.Status -eq "Running"}).Count
Write-Host "Self-Service VMs         :", @($VMs | where {$_.SelfServicePolicy -ne $null}).Count
Write-Host "VMs without VMAdditions  :", @($VMs | where {$_.HasVMAdditions -eq $false}).Count

####################################################################
# Summary of Self-Service
####################################################################
$SelfServicePolicies = @(Get-SelfServicePolicy)
$VMs = @(Get-VM)

Write-Host "`nSELF-SERVICE" -ForegroundColor Yellow

Write-Host "Self Service Policies   :", $SelfServicePolicies.Count
Write-Host "Total Self-Service VMs  :", @($VMs | where {$_.SelfServicePolicy -ne $null}).Count
Write-Host "Hosted Self-Service VMs :", @($VMs | where {$_.SelfServicePolicy -ne $null} | where {$_.Status -ne "Stored"}).Count
Write-Host "Stored Self-Service VMs :", @($VMs | where {$_.SelfServicePolicy -ne $null} | where {$_.Status -eq "Stored"}).Count

####################################################################
# Summary of Library Servers
####################################################################
$LibraryServers = @(Get-LibraryServer)
$VMs = @(Get-VM)

Write-Host "`nLIBRARY SERVERS" -ForegroundColor Yellow

Write-Host "Library Servers :", $LibraryServers.Count
Write-Host "Stored VMs      :", ($VMs | where {$_.Status -eq "Stored"}).Count

####################################################################
# Summary of Virtual Machine Host Groups
####################################################################
$VMHostGroups = @(Get-VMHostGroup)
$VMs = @(Get-VM)

Write-Host "`nVIRTUAL MACHINE HOST GROUPS" -ForegroundColor Yellow

foreach ($VMHostGroup in $VMHostGroups)
{
    $VMHostCount = $VMHostGroup.Hosts.Count
    $VMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost}).Count
    $RunningVMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost} | where {$_.Status -eq "Running"}).Count
    $SelfServiceVMCount = @($VMs | where {$VMHostGroup.Hosts -contains $_.VMHost} | where {$_.SelfServicePolicy -ne $null}).Count

    Write-Host "Host Group                :", $VMHostGroup.Name
    Write-Host "Number of Hosts           :", $VMHostCount
    if ($VMHostCount -ne 0)
    {
    Write-Host "Number of VMS             :", $VMCount
    Write-Host "Running VMs               :", $RunningVMCount
    Write-Host "Self-Service VMs          :", $SelfServiceVMCount
    Write-Host "VMs per Host              :", ($VMCount / $VMHostCount)
    Write-Host "Running VMs per Host      :", ($RunningVMCount / $VMHostCount)
    Write-Host "Self-Service VMs per Host :", ($SelfServiceVMCount / $VMHostCount)
    }
    Write-Host
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft