Yup you saw that right PowerShell can be used to manage and work with your VMware environment. Specifically you use the PowerCLI when you want to manage your VMware vSphere environments. PowerCLI is a very popular third-party implementation of PowerShell. PowerCLI is a snapin for Microsoft PowerShell and you can get it here: VMware vSphere™ PowerCLI. When it comes to managing your VMware environment with PowerShell it just makes sense. While I would love for customers to use Hyper-V, the fact you can manage VMware with PowerShell I find interesting. More importantly the amount of work to make a robust PowerShell toolset for VMware is pretty impressive.
Working with the PowerCLI is the same as working with any PowerShell cmdlets and scripts. You can connect to your servers with Connect-VIServer. You can then also run these cmdlets to help get a list of inventory in your environment: Get-VM and Get-VMHost As you may imagine you have several cmdlets to work with several other aspects of a VMware environment like Start-VM & Stop-VM for hard power operations. With Restart-VMGuest you can perform a soft-reboot. So how can you find all of the cmdlets you can use in PowerShell after you have installed the snap-in you can run this cmdlet:
Like other PowerShell cmdlets the VMware cmdlets also have built in help to learn the various cmdlets, and you can also get an online version, the following two cmdlets will show the help for the Get-VM cmdlet:
- help Get-VM
- help Get-VM –online
To learn more of the basics, this is a great place to start: Getting Started with PowerCLI 4.1 – Automating Your vSphere Environment. Another good resource on VMware’s site is here: VMware vSphere™
I would also highly recommend Managing VMware Infrastructure with Windows PowerShell TFM by Hal Rottenberg. I have had a chance to meet Hal and he really knows his stuff and I recommend checking out his book. Keith Combs and I also had a chance to interview Hal on our radio show. You can check out the replay here: Talk TechNet - Episode 23 - PowerShell with Hal Rottenberg (4/20/2011)
From the publisher: This book is great for the VMware admin wishing to automate their environment with PowerShell. Again, Hal has an entertaining writing style and makes learning this topic very enjoyable. There are many practical examples in this book which you will find really useful in your environment.In "Managing VMware Infrastructure With Windows PowerShell", you will learn how to perform everything from simple ad-hoc reporting at the command-line ("Are any of my virtual machines powered off?") to complex scripts to automate a massive deployment of hundreds of virtual machines. Simple, yet powerful; concise, yet robust; you will enjoy using this new language to solve your old problems using less code than you thought possible. If you are a system administrator responsible for managing a VMware Virtual Infrastructure (version 2.0 or above), or a standalone ESX Server (version 3.0 or above), then you need this book. Aimed at scripters of every level, the book starts off with a PowerShell primer and continues well into the internals of virtualization on the VMware platform.
Also in my research for this post I stumbled upon a great article from April 2010: Five must-have vSphere PowerCLI scripts. I summarized the 5 here, check out the article for some more background:
- vCheck (Daily Report) V3 With this script, you can have a daily summary of your virtual environment sent to your email inbox.
- Who created that VM? By adding custom fields to each VM, this PowerCLI script provides data on the VM's creator and creation date in the VM's annotations.
- vSwitch port overview To check how many ports each vSwitch uses, run this PowerCLI script. Then, make the proper adjustments to your virtual switches.
- Report into Microsoft Word This script not only automates the reporting process for an entire virtual environment but it also exports the data into Microsoft Word with colorful graphs and pie charts.
- Customizing Site Recovery Manager plans This script shows how to run PowerCLI on SRM servers and presents a script that reduces the amount of RAM used by VMs during the recovery process.
Thanks for reading and if you missed any of the previous posts you can find a master list of series postings located here: PowerShell Not Your Father's Command Line: 31 Days of PowerShell or on Sarah’s blog here: PowerShell Not Your Father's Command Line: 31 Days of PowerShell. Lastly Sarah and I want to hear from you email either of us with your comments or suggestions for future postings let us know, we look forward to hearing from you. Have a great day!