Today we have a post about the vSphere PowerCLI from Arun Pandey, who is a Tech Support Engineer in our Bangalore, India office. Arun is currently focusing on Knowledgebase content creation. This post provides you with an overview of the PowerCLI and how you can benefit from it by automating tasks.
I have started writing this blog with introduction to ESXi because there is no Console Operating System (COS) provided in ESXi, and Administrators who are used to the COS might find transitioning to ESXi difficult.
In December 2007, the first version of ESXi was released, with no service console, reducing the size of ESXi to under 32MB. The ESXi server is able to boot off an embedded USB key so you can completely forget about issues with local storage (faulty disk, raid controller & updating firmware). With the Service Console gone ESXi improves both reliability and security.
I am impressed with all these advantages but the biggest question is about managing your ESXi host. With the service console gone, how would I perform the administrative tasks for vSphere components?
After researching for about a week, I found that vSphere PowerCLI could be used to perform all the administrative tasks. Now I can not only perform regular tasks but I can also automate them. With PowerCLI to automate tasks, you don’t have to be a Developer/Programmer anymore, you don’t have to spend time writing the if..else, do…while loops, assign variables, to get work done because PowerCLI is distributed as a Windows PowerShell snapin, and includes more than 200 PowerShell Cmdlets (commands). It becomes much simpler to use these cmdlets (the Get-<Command> to gather information, and Set-<Command>) to configure vSphere components.
Installing PowerCLI is as easy as pie, download the binary and install it and you are all set to use the PowerCLI.
There are few prerequisites to getting all the peices working(Installing .Net Framework and Power Shell 1.0/2.0), for more information see our vSphere PowerCLI Installation Guide.
A good place to start is the following article to get an overview: Managing storage using PowerCLI (1028368). That will soon have you:
- Collecting information about the virtual machine
- Configuring the virtual machine (Get-VM and Move-VM can do mass vMotion & Storage VMotions)
- Working with virtual machine snapshots (Get-VM & New-Snapshot can take snapshots for all the Virtual Machines in the Cluster/Datacenter)
- Updating VMware Tools (Get-VM & Update-Tools can upgrade the Virtual Machine tools on all the Virtual Machines in the Cluster/Datacenter/Resource Pool)
Earlier, when I had to patch all my Windows Virtual Machines in my inventory, I had to manually take snapshots for them, a daunting task (i.e. taking snapshots on 100+ VM’s individually) but now, all I have to do is run:
Get-Cluster "vCloud" | Get-VM | New-Snapshot -Name Automate
from vSphereCLI and enjoy my coffee. Snapshots are created for all the Virtual Machines automatically. After installing the Windows patch I was installing I used the same trick to delete snapshots:
Get-VM | Get-Snapshot | Remove-Snapshot
to delete them.
For folks wondering how they can check logs and troubleshoot ESXi servers without a console check Collecting diagnostic information using the VMware vSphere PowerCLI (1027932).
Amazing!! It reminds me about the Industrial Revolution when machines replaced manual labor. Today, GUIs are supplemented with CLIs, and with the amount of time that I saved, I’m planning to continue to explore our CLI.
Now I no longer fear how I can manage my ESXi servers without a service console, and I strongly recommend learning the vSphere PowerCLI to you.
0 comments have been added so far
Why use a Windows tools for this.
Also, doesnt Update Manager give an option to take a vm snapshot before applying updates and then delete them automatically after some days. Why use Power CLI??
Thanks Arun. The info that you have given has been very useful. Appreciate the way you have mentioned the steps with the snapshots.
Good Job Arun. Thanks for sharing 🙂