PowerCLI Series – Getting Started

Hello all,

I want to help everyone get more out of PowerCLI.  So I am going to work through a short series on getting started with it, and doing a number of different things with it.  This is more about being a consumer, rather than a developer.  But it will get you going.

Why PowerCLI?  Because it is easier to do some things, in an automated way, and that means less errors.  As compared to doing a bunch of edits.  Plus, there is a lot of help and examples out there.  So for us, in this series, I am going to start with getting PowerCLI working, than setting NTP and Syslog parameters using a script.  More likely to be done with no errors this way.  But we will do some other things along the way that I think will be useful.

You should find, and download the PowerCLI bits from here.  As well, we are going to start with using Notepad++ as our editor so get those bits here.

Now where to install.  Generally there is two places.  The first is your admin desktop.  It is in fact a View desktop for me.  But, there will be scripts that are executed on a schedule, and that is generally not good for your desktop.  So the second place is where you will not normally log in and can use as a script execution location.  In my lab it is on one of my AD DC’s.  We will need this for one of the very special scripts we are going to get going in this series.

Installing PowerCLI

You will be potentially prompted by the system to install VMware VIX.  This is a key component so make sure it gets installed as well.  So essentially there is two installs.  When I install PowerCLI on my work desktop I use all defaults.  I love how we get details when PowerCLI is being installed.  When I was at VMware I tried to get more installer teams to do this.

PowerCLI Install

Once everything is installed, you will need to start PowerCLI and type something to make sure your scripts will execute as you expect.  You can find a new icon on your desktop to start PowerCLI.  It looks something like below.


You will also find a VMware vSphere PowerCLI group in the VMware group in All Programs.  However, this first time into PowerCLI you should make sure to start it with Run as Admin.  So right click on the icon on the desktop and select Run as admin.  Now you will enter the following command:

Set-ExecutionPolicy RemoteSigned

This will allow scripts you created or find and modify to be executed.  But downloaded scripts will need to be signed.  This does not mean copy and paste type downloaded scripts need to be signed.   Once this is done it should like something like below.


We now have a working PowerCLI world.  But there are some tweaks to make it better.

I use c:\scripts to keep all my scripts in.  Both on my desktop and on the DC where I will do the scheduled script executions. We will create a PowerShell profile to make sure we always start in this folder.  From within PowerCLI you should type the following:

New-Item -path $profile -type file -force

Now you can use the command below to actually open your profile and look at it.

notepad $profile

Right now we only want to add one thing to it.

Set-Location C:\Scripts

Now save the file and exit PowerCLI.  When you come back in you should be in that folder.  I found out how to do this sort of thing from this here.  If you want to make even more changes to your profile than check this out.


We need a nice tool to work with the scripts.  There are a few around, but for now we are going to use Notepad++.  I like it, and it has pretty colours so it works fine.  Again I install with defaults.

Good things to know

You can work interactively in PowerCLI.  Meaning start it up, and type commands.  You can also create scripts in Notepad++ and save them to the c:\scripts folder and execute them.  I generally try to not work interactively but use scripts.  If you work interactively remember you can use the TAB key to complete which is very helpful and can help avoid errors too.

We will start with working interactively.  Once you are in PowerCLI use the command below to connect to your vC.

Connect-VIServer vC_server_name

You will see a bunch of stuff go by.  Something like below.  I will figure out the issue in yellow and share how to deal with it.


The thing to note is at the bottom and that is it shows that my account is now connected.  Now lets find out what VMs this vC can see.


PowerCLI, or rather PowerShell is not case sensitive.  I just like typing things like that.  Now you should see something like below.


This is working interactively.  Now lets work like a script.  Use Notepad++ and put Get-VM into it and save it as vm.ps1.  Now check this out.


See how I used the cat command to see what was in the file?  And notice how I executed it?  I am told that is a best practice.

We want to use scripts.  Safe and more flexible.  Plus, they can be smarter than we are!  We will have an example of that later.

So this is the end of this Getting Started.  Next one will be about using some scripts to accomplish real things.

BTW, I suggest you watch this blog, this one, and this one.  They often have some good stuff.


  • 9/17/16 – here is an article with some very good learning info and suggestions.


Tagged with: , ,
Posted in How To

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: