PowerCLI is an extremely powerful (hence the name way of managing your VMware infrastructure. It is a set of additional cmdlets for MS PowerShell that extend PS to managing VMware environment. Please explore Microsoft resources if you would like to know more about PowerShell itself – how to install it, how to run it, etc. Here I’ll assume you have your PS already installed and you know how to open it You can probably run a script downloaded from the Internet or copied from a site but if you’d like to see how PowerCLI works and how to write your own scripts – this place is right for you. If you manage a significant number on VMs on even a few hosts believe me, there will be situations when PowerCLI will save a lot of time for you.
Let’s start with VMware PowerCLI site where you can find both PowerCLI for download and huge amount of information – from ready scripts to discussions to white papers and posters. The installer is about 90MB in size – go and grab it. The instalation itself is pretty straightforwad and consists in clicking Next. The only thing that can suprise you might be the following window:
So what as just happened? Basically the installer tells you that the script launch policy on your computer might make running downloaded scripts, or any scripts in fact, impossible. Click Continue button and go ahead with the installation. When PowerCLI is being installed on your computer, open PowerShell and put the following command:
You may get as a response „Restricted”. Aha! So this is what the warning was talking about. Basically in PowerShell you can set your script execution policy to 4 different levels. It will influence your ability to run different scripts:
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted – No restrictions; all Windows PowerShell scripts can be run.
[info via http://technet.microsoft.com/en-us/library/ee176847.aspx]
You can change it with Set-ExecutionPolicy cmdlet followed with the level appropriate for you. More information can be found directly in PowerShell via Get-Help about_signing cmdlet.
By this time PowerCLI should be already installed. Take your time and look for it under VMware > VMware vSphere PowerCLI in your start menu. Got it? Good.
In order to do anything useful we need first to connect to the server. What server? It can be both your ESX/ESXi host and vCenter Server. You do it with one command:
When you hit enter PowerCLI is oing to ask you for the server’s address or name, login and password. You can pass all these parameters at the same time:
Connect-VIServer -server [Your_server_IP] -user [Your_username] -password [Yeap_your_password_here]
Now, once connected to the server we can unleash the whole power of PowerCLI. Next time we will see how to find useful cmdlets, how to learn about them and how to pass the information from one cmdlet to another. Execute the following command
to disconnect your PowerCLI. Stay tuned for a next part.