Just Another IT Blog

It's time to share some of my experiences, crazy ideas, tips and tricks !!!

Post Page Advertisement [Top]

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

Bottom Ad [Post Page]