Book Image

System Center 2012 R2 Virtual Machine Manager Cookbook - Second Edition

By : Edvaldo Alessandro Cardoso Sobrinho, EDVALDO ALESSANDRO CARDOSO
Book Image

System Center 2012 R2 Virtual Machine Manager Cookbook - Second Edition

By: Edvaldo Alessandro Cardoso Sobrinho, EDVALDO ALESSANDRO CARDOSO

Overview of this book

Table of Contents (18 chapters)
System Center 2012 R2 Virtual Machine Manager Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using VMM sample scripts


The sample scripts in this recipe illustrate how to use Windows PowerShell for centralized management.

You can use VMM PowerShell cmdlets to automate VMM tasks by executing them from a machine that has the VMM console installed.

The following section contains some samples to add storage and convert the VHD disk format to the VHDX disk format.

How to do it...

You can use PowerShell scripts to automate various tasks. The following section will help you with the sample script that counts the number of Virtual Machines per Operating System (VMs per OS).

Counting the number of Virtual Machines per Operating System

The following script will count the VMs per OS:

Import-Module virtualmachinemanager
$vHosts = Get-SCVMHost
foreach ($vHost in $vHosts){ 
   Get-SCVirtualMachine -VmHost $vHost | Group-Object OperatingSystem | Sort Count –Descending | Select Name, Count
}

The following image shows the script output:

How it works...

The script starts by importing the virtualmachinemanager...