TONYSO

Tonyso Credo: "Look for a pattern, and solve it for everything"

VMM: Scripting Guide Goes Live

VMM: Scripting Guide Goes Live

  • Comments 1
  • Likes

The VMM Scripting Guide is now available in the download center. The Virtual Machine Manager Scripting Guide explains how to create Microsoft Windows PowerShell scripts that execute Virtual Machine Manger 2007 commands, and provides more thatn 100 pages of useful sample scripts, including:

  • Sample Script for Upgrading Hosts and Library Servers
  • How to Convert an Existing Cmdlet Help Example to a Script
  • Sample Scripts for Managing Virtual Machines
    AutomateNewVMCreation.ps1
    InstallVMAdditions.ps1 
    ConfigureGuestCluster.ps1
    How ConfigureGuestCluster.ps1Works 69
    NewVMScriptFromWizard.ps1
  • Sample Scripts for Backing Up and Restoring the VMM Database
  • Sample Script for Integrating VMM with OpsMgr

For example, the SummarizeVMMInformation.ps1 script displays a summary or information about your VMM environment.

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

Comments
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment