Tuesday, April 27, 2010

Install and use PowerCLI

VMware vSphere PowerCLI is a powerful command line tool that lets you automate all aspects of vSphere management, including network, storage, VM, guest OS and more. PowerCLI is distributed as a Windows PowerShell snapin, and includes more than 150 PowerShell cmdlets.
This scripting tool is gaining popularity day by day because of its easy to use architecture and it equips administrator who are good at scripting to manage their environments the best way.

Softwares needed:

1. Powershell
2. vSphere PowerCLI -4.0

Installation of PowerShell on windows box is pretty easy. But with PowerCLI you may face certain issue post installtion which are discussed below.
Note: My Post is based on installation in Vista and I will be discussing issue specifically in that regard.

Issues during Installation and configuration of PowerCLI:

A) In Vista, While installation of PowerCLI a warning might be issued regarding the “ execution policy for running Power CLI”.



Solution: proceed by clicking continue, this warning is taken care after installation.

B) After installation of PowerCLI and before you start using change the execution policy from “Restricted” to “Remote Signed”. Otherwise even if you open the PowerCLI prompt you won’t be able to work on it. It will fail with below error in red…



Solution: Open PowerShell console as administrator (right click on PowerShell icon and select run as administrator)
Enter the command: Set-ExecutionPolicy RemoteSigned

Note: If you run as normal user this won’t work and will throw permission error.

After running above command you can use PowerCLI console by running cmdlets/commands to manage your vSphere environment.

Eg:> Connect-VMServer

Now try running the above command in PowerShell console….I don’t want to have two consoles one for PowerShell and another for PowerCLI so I have decided to have PowerCLI used from PowerShell Console itself. For that we need to add the PowerCLI snap-in to PowerShell which is achieved by running the below command in PowerShell.

D:/>get-pssnapin -registered | add-pssnapin –passthru

This will check all the registered snap-ins on PowerShell and add any new ones, in our case PowerCLI snap-in.
Now you should be able to run all the PowerCLI cmdlets from PowerShell itself.

But this addition is not persistant and once you close the powershell console and open a new one you have to run the above command again...
I googled a little bit and tried a trick of windows which worked.

Below steps can help in making the addition of snap-in permanent.
1. open powershell console
2.add powercli snap-in using command " get-pssnapin -registered | add-pssnapin –passthru "
3.now export the console configuration to a file by running below command.
export-console
a config file with the mentioned name will be created in the current directory.
4.now right click on powershell application icon --> open "Properties" --> select tab "shortcut"
5.Edit the lines in "target" section with
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -psconsolefile C:\Users\prudhvi\file_name.psc1
Note: filename should be specified with full path.
6. Click 'ok'

From now onwards whenenver you opent the Powershell console its comes added with PowerCLI.

My intention of providing this info is to help people who like me are beginners and also facing similar problems that i bumped into. Hope the above info was helpful to kick off with PowerCLI

Keep following this page as i'll be updating this post while i learn more about PowerCLI and use it more in my VMware Environment...

Happy Virtualizing....
-
Penguin ;)

Friday, April 23, 2010