Okay, maybe not, but whether you are new to Windows PowerShell scripting or consider yourself an expert, the System Center Virtual Machine Manager 2008 Scripting Guide is for you!
Because System Center Virtual Machine Manager (VMM) is built on Windows PowerShell, any action you that can do in the UI is an action you can also do using VMM cmdlets. The Scripting Guide provides examples of how to automate tasks and augment the functionality of the product. If you're new to using VMM cmdlets, start by visiting the Introduction to help get your bearings. There, you can discover how to:
· Add the VMM snap-in.
· List all VMM cmdlets.
· Use VMM cmdlets.
· Connect to the VMM server.
After you have explored the VMM cmdlets that are available to you, you can peruse the remaining sections, which contain examples for managing the various aspects of VMM such as hosts, virtual machines, and a VMware environment.
One of the goals of the Scripting Guide is to help administrators write scripts that can be used to perform repetitive tasks. For example, if you want to create a virtual machine, you can do this using the UI. However, you can only create one virtual machine at a time. If you want to create, say, 50 virtual machines, it would take quite a few trips through the New Virtual Machine wizard to accomplish this. However, we have provided a couple of scripts that you can use to create multiple virtual machines. If you want to use a template to create virtual machines, check out CreateNewVMsFromTemplate.ps1. After you specify the template you want to use, and the number of virtual machines to create, the script will take care of the rest. Or, if you want to create virtual machines from scratch, you can use CreateNewVMs.ps1. This script creates a hardware profile, a guest operating system profile, and a template using these profiles. It then creates the number of virtual machines you've specified, and deploys each of them to the host with the highest rating.
You may have heard about rapid provisioning. This is a feature of VMM 2008 R2 where you can create a virtual machine from an existing hard disk file stored locally on a destination host instead of copying it from the library, which saves time when creating the virtual machine. This feature is only available using the VMM cmdlets, not through the UI. The script entitled RapidProvisionVM.ps1 walks you through the process. If you have an answer file that you'd like to use during virtual machine creation, you can use the RapidProvisionVMwithAnswerFile.ps1 script.
We've also demonstrated how to use core Windows PowerShell cmdlets in a VMM environment. For example, CheckForPendingReboot.ps1 imports computer names from a CSV file, looks for the RebootPending registry key on those computers, and, if present, restarts the computers for you. This script contains no VMM-specific cmdlets; however, this task is very useful in the VMM environment.
Another script that combines core Windows PowerShell cmdlets with VMM cmdlets is SignScriptsInLibrary.ps1. You can store your scripts in the VMM library, but if your Windows PowerShell execution policy is set to run only signed scripts, you must sign all of the scripts in the VMM library before you can run them. The SignScriptsInLibrary.ps1 script looks for all scripts you have stored in your library and signs them for you. But, don't forget to sign SignScriptsInLibrary.ps1 prior to running it, or it will fail on you!
We've also built script-based suggestions from customers. For example, VMM does not automatically perform load balancing among hosts in a cluster. However, based on a request from a customer, we created the LoadBalanceVMsInCluster.ps1 script, which uses the available memory of hosts in a cluster in conjunction with the memory usage of the virtual machines to balance the load across the cluster. As a matter of fact, the CheckForPendingReboot.ps1 script mentioned earlier was also a suggestion from a customer.
If you have any comments on the VMM 2008 Scripting Guide, or suggestions for future scripts, please send e-mail to mailto:%firstname.lastname@example.org?subject=Scripting%20Guide. You can also download the VMM 2008 R2 Scripting Guide to read it offline.
Susan Hill, Senior Technical Writer, Microsoft