Friday, November 5, 2010

VMware PowerCLI Basics

I realized that every post about PowerCli I write I need to give the same instructions: Install, configure, etc…

So, I’m creating this post with the basics of PowerCli and in the future I will always make reference to this post.

Let’s get started:

Make sure you have PowerShell installed (newer O.S. already have it, if you don’t have it go to Microsoft web page download and install it.)

Then you need to install PowerCLI, download it here. (the installation is pretty much the same…Next..Next..Finish)

Now, that it’s installed, you just need to launch, there should be a shortcut on your desktop or through the Programs Menu under VMware

First thing you need is to connect on your Virtual Center.
- Run: Connect-VIServer –Server “your_VC”

Then you can place all the command and scripts

Exporting the results:
To export the results you can:

1. after the command add “ > file”
ex: Get-VM > c:\temp\result.txt

2. export to a csv file. After the command add “ | Export-CSV your file”
ex: Get-VM | Export-CSV c:\temp\result.csv

Working with batch files
PowerCli can also work with batch files, so you can create scripts and run them against just some specific serves.

- create a txt file with one host per line (ex: c:\temp\servers.txt)

Then you can read this for the source of hosts:

Option 1:
Reading the file to a variable
- Run: $host = Get-Content c:\temp\servers.txt
Running the command against the variable
- Run: Get-VM $host

Option 2:
Reading the hosts direct from file
Get-Content c:\temp\servers.txt | foreach { Get-VM $_ }

Here you go, now you are ready to play with PowerCli, the basic syntax is there, you just need to change the commands you need to run and adjust any additional parameter you might want.

See you next

1 comment:

Unknown said...
This comment has been removed by the author.

Post a Comment

Who am I

My photo
I’m an IT specialist with over 15 years of experience, working from IT infrastructure to management products, troubleshooting and project management skills from medium to large environments. Nowadays I'm working for VMware as a Consulting Architect, helping customers to embrace the Cloud Era and make them successfully on their journey. Despite the fact I'm a VMware employee these postings reflect my own opinion and do not represents VMware's position, strategies or opinions. Reach me at @dumeirell

Most Viewed Posts

Blog Archive