yoyoclouds

just another cloudy day….

VM Report- PowerCLI Script

VM Report- PowerCLI Script

This is a pretty straight forward script written in PowerCLI..

This script will generate an Excel sheet with some VM information in it… For E.G. it will color the cell red if the Power State of a VM equals to NotRunning… or if the version of VMware Tools installed in it are old/ outdated..

YOU CAN DOWNLOAD THIS SCRIPT FROM HERE

NOTE: To run the script, simply copy the contents from the PDF and paste it in a new file with the extension as “.ps1

To run the script:

  1. You will require PowerCLI to be installed on your local machine
  2. Administrative rights to run the script as well as administrative rights to your vCenter Server

Steps to run the script:

  1. start your PowerCLI command line tool
  2. go the the directory where you have saved the script (In this case, i have saved it in D:/scripts folder)
  3. run the script
  4. when the script executes, it will ask you to enter your vCenter IP (In this case, its 172.31.72.19)
  5. provide the IP and hit enter key.

  1. it will prompt you to enter your vCenter credentials. Provide your Administrative credentials.

  1. once you provide your correct credentials, the script will start execution.
  2. it will display a Excel sheet with a Header row and some data in the beginning. Eventually it will be populated as the script gathers more info from your vCenter. a Demo Output image is shown below:

Advertisements
Leave a comment »

PowerCLI and vCloud Director: How To Videos

PowerCLI and vCloud Director: How To Videos

VMware PowerCLI 5.0.1 vCloud Director Basic Usage

A video showing PowerCLI 5.0.1 and vCloud Director Basic Usage.

VMware PowerCLI 5.0.1 vCloud Director Cmdlets – Stopping and Starting vApps

A video showing how to retrieve and use some of the methods on the vCloud Director objects taking the 5.0.1 release of PowerCLI further and stopping and starting vApps.

VMware PowerCLI 5.0.1 vCloud Director Cmdlets – Creating New vCloud Organizations

This video was presented as part of the “vCloud Infrastructure Automation – powered by PowerCLI” presentation presented at Partner Exchange 2012 in Las Vegas. It shows how to use VMware PowerCLI to create new vCloud Organizations, Users and Org vDC’s.

Leave a comment »

Getting Started with VMware PowerCLI

Getting Started with VMware PowerCLI

With vSphere 5, the traditional ESX Server has gone away and the permanent replacement is ESXi Server. Of course, the big difference is that ESXi Server doesn’t have a service console. That service console was a special privileged virtual machine that was used for administration and scripting functions for an ESX host. ESXi Servers, with their tiny Busy-box Linux super-slim console isn’t going to work for scripting and isn’t efficient for mass administration & configuration of ESXi Servers.

VMware recommend one of two options with one being the vSphere Management Assistant (vMA). For information on vMA, see my video “Using the vSphere Management Assistant”. However, scripting in vMA will be done, very likely, using Perl. For most VMware Admins, Microsoft’s PowerShell is a more appealing option as it works for a wide range of Microsoft and third-party products. Thus, your knowledge of PowerShell would allow you to script Windows Server tasks, Exchange Server tasks, and more. Well, that “more” is also VMware vSphere server tasks. When you use PowerShell with VMware’s “cmdlets”, it’s called PowerCLI and that is the best option for mass vSphere administration and scripting.

What You Need to Use VMware PowerCLI

Minimally, to use VMware PowerCLI, all you have to do is to download and install the VMware PowerCLI application (free). You can download this from the VMware PowerCLI Community site.

Make sure that you download version 5.0 or later (5.0.1) because, at the time of writing this article, version 5.0.1 is the latest and is compatible with vSphere 5.

This community site offers a lot more than just the PowerCLI software. They also house:

  • The official VMware PowerCLI documentation
  • A free PowerCLI Workshop presentation and scripts
  • A link to the PowerCLI Blog (lots of good script examples there)
  • PowerCLI sample code
  • A discussion forum where you can post your PowerCLI questions

Downloading and Installing VMware vSphere PowerCLI

As I said, PowerCLI is actually just a simple Windows installation. Downloading it will require a free VMware account but will only take a few minutes. The 91MB download may take longer to download than it takes to actually install.

Once downloaded, here’s what the installation looks like:

During the installation, you may see a message that looks like this. If you do, you can click continue but you will have to resolve this later.

Once installed, you’ll have a group of programs under your VMware program group that looks like this:

To actually run PowerCLI, you would run the program described as VMware vSphere PowerCLI and here’s what you would see:

Initially, a black window with a command prompt is very intimidating for new PowerCLI admins so please don’t get scared off at this point. You don’t have to spend your whole PowerCLI life at this command prompt. There are easier ways to use PowerCLI (and I’ll show them to you later).

First, let’s fix that nasty-looking red error (the same error that popped up during installation).

Fixing PowerCLI Execution Policy Errors by Setting RemoteSigned

I’m not going to claim to be an expert on PowerCLI security nor am I even going to go into the different PowerCLI execution policy settings that are possible. Instead, I’m just going to show you how to resolve this error the quickest way possible so that you can run some PowerCLI scripts.

This annoying error seems to come up every time I go to run a PowerCLI script and I always have to Google what I need to do to resolve it. This is likely because I never fix the issue permanently and because I don’t get the opportunity to use PowerCLI as much as I would like (I don’t have a large production environment like many of you have). So, let’s not only fix this PowerCLI execution policy error but also do it “once and for all”.

As the GUI error message said when we were installing PowerCLI, to resolve this, you simply need to set the PowerCLI execution policy to remotesigned. To do it, use the same command prompt that you see in the Window in Figure 7 and type:

Set-ExecutionPolicy RemoteSigned

Here’s what it might look like:

NOTE: If it didn’t work.. Why is that? It can be because you didn’t have access to the registry, you couldn’t set this. To set this successfully, you have to open the PowerCLI prompt as Administrator (or equivalent).

PowerGUI, VMware Community PowerPack, & Project Onyx – Must Have Tools

Now that you have the required PowerCLI installed and the correct security policy, you need the single tool that is going to make using PowerCLI easier. Using PowerCLI from that unhelpful and boring old black command window reminds me of using MS-DOS. Trust me, that’s not how you want to use PowerCLI.

The single tool that you must have to use PowerCLI productively, luckily, is completely free and comes with a ton of pre-created scripts. That tool is PowerGUI and it includes the VMware Community PowerPack. You can download it from PowerGUI.org and the install is your quick and customary Windows install process.

Resources for Learning PowerCLI

Leave a comment »

%d bloggers like this: