Tag Archives: Windows Powershell

vCloud Director Snapshots with PowerCLI

If you or your provider are already running vCloud Director 5.1, you now have access to take a single snapshot of your VMs!

If you want to play with snapshots in PowerCLI, you’re going to need the module in this blog. PowerCLI 5.1 currently only supports the vCloud API 1.5, which means there are no 5.1 API capabilities yet. (I stress “yet.” :D)

The module uses the current PowerCLI for it’s session and API access, and then bolts on some 5.1 API snapshot magic.

To use the module, simply download the .psm1 file and:


Import-Module vCloudSnapshots.psm1

After that, you’ll have access to 4 cmdlets:


Get-CISnapshot
New-CISnapshot
Remove-CISnapshot
Set-CISnapshot

To get snapshots:


# Get vApps with Snapshots
Get-CIVapp | Get-CISnapshot

# Get VMs with Snapshots
Get-CIVM | Get-CISnapshot

# Get Snapshot info for a particular VM
Get-CIVM "MyVM" | GetCISnapshot

It should be noted that all the cmdlets apply to a VM or vApp, so always make sure you’re doing a Get-CIVM or Get-CIVapp first.

For example…here’s creating, reverting, and removing:


# Create a snapshot for a vApp (or all VMs in the vApp, really.)
Get-CIVApp "MyVApp" | New-CISnapshot

# Revert to our snapshot
Get-CIVApp "MyVApp" | Set-CISnapshot -revertToCurrent

# Remove our snapshot
Get-CIVApp "MyVApp" | Remove-CISnapshot

For more help, just use Get-Help and the command!

vCloud Snapshots Powershell Module


Uploading VMs to vCloud with OVFtool

VMware’s OVFtool is a command line tool that allows you to convert VMware Virtual Machines to Open Virtualization Format, or OVF. In the latest version, it can also upload VMs to vCloud Director for you as well!

To do this, OVFtool simply requires a source (VMX or OVF), and a destination (a vCloud Locator).

The vCloud locator looks something like this:

vcloud://username:password@host:port?org=name_of_org&vapp=name_of_deployed_vapp&catalog=name_of_catalog&vappTemplate=name_of_vapp_template_in_catalog&vdc=name_of_vdc

As you can see, the vCloud Locator is a URL with all of the information needed to upload your OVF.

Because OVFtool is run from the command line, the simple choice when using Windows is to use the command prompt. Using the Windows command prompt, however, results in errors when uploading to vCloud Director:

ovftool error

ovftool error

This is most likely because of the special characters ovftool uses in the URL (&, :, ?, @). If I had to guess, I’d say it’s the ampersand.

I tried quoting out the vCloud Locator several different ways to get it to understand, but resorted to Powershell to save the day once again.


$vCloudLocator = "vcloud://jake:password@vcloud.example.com:443?org=jake&vappTemplate=MyTemplate&catalog=private"

$sourceFile = "C:\jake\MyVM.vmx"

$ovftool = "C:\Program Files\VMware\VMware OVF Tool\ovftool.exe"

& $ovftool $sourceFile $vCloudLocator

Powershell treats the characters are part of the string, so we just simply pass the string as a parameter to OVFtool.

Hope this saves someone a headache! 😀

For more OVFtool fun, check out my post on using OVF tool with PowerCLI with your vSphere session!


How to be a PowerCLI Ninja

Dean (aka @Danger0u5) mentioned on twitter that he’d like to be a Powershell/PowerCLI ninja someday. (I think he’s already on his way. :)) It got me thinking about how I got started with Powershell and what my core success factors were with learning it. These tips can apply to learning almost anything, really!

1. Make it a priority.

My mentor and Bluelock CTO Pat O’Day (maybe unbeknownst to him :)), caught me once saying “I wish I had the time…” Very understanding to my dilemma, he said “You will never have enough time. It’s about priority.” That simple fact might be obvious to a lot of people, but it absolutely changed my views about time vs. priority. “I don’t have time” doesn’t exist for me anymore. It’s all about where it lands in the list. “Hey Jake, can you {Insert task here}?” “I can do that, but lets figure out the priority.”

The point here? You have to decide the priority of learning this new skill. Ask yourself “How important to me is learning Powershell/PowerCLI?” I can tell you from experience it is well worth it, but you need to decide for yourself. After that, it will be fairly simple to fit it into your list.

2. Focus on a specific task.

I learned Powershell because I had an idea. A need. I wanted learn to Powershell to accomplish something very specific. So, I mapped out in my head the various bits of information that I would need, and then learned how to get that information with Powershell. Then it was just math and formatting. There are a lot of great books, blogs and online training regarding Powershell/PowerCLI, but if you don’t have a specific need, you aren’t going to retain the information.

I’ve been struggling learning Ruby (and Rails). I really want to learn Ruby (and Rails). The problem is, I don’t have a specific need. I’ve been through tryruby.org and Rails for Zombies, which are both GREAT free tools to learn Ruby (and Rails), but the moment I leave the page, it’s gone. There are a few reasons I want to learn Ruby, but again, nothing that is specific enough, or high enough priority.

For those struggling to learn Powershell/PowerCLI, don’t be discouraged. Focus on a very specific need. For those struggling to find a specific need, talk to people around your office. Groans and sighs are good places to start. Listen for phrases like “It’s going to take me 12 hours to put this data in.” Another good place to look for inspiration is the forums. Look for tumbleweed type questions (those that have somehow slipped the view of Luc Dekens. ;)) I’ll lurk the forums once in a while looking for things I find interesting. Even if they are already answered, I can look at how the problem was solved, and see if I would have answered it the same way.

3. Don’t be afraid to ask for help, but know how to ask good questions.

It surprises me how often I answer my own questions just by typing it up, and reading it as if I were answering for someone else. When I ask a question, I really try to understand what information someone would need to answer it. I want to equip the answerer with enough information to get me the right answer the first time. There can be too little information, but worse there can be too much information. Understanding the real issue is the key to getting a correct answer.

Back in my telecom days, there was a tag always attached to a piece of equipment that, in large bold font said “DO NOT ASSUME ANYTHING.” I always had a chuckle about it, but it’s a life rule Engineers should live by. Don’t assume thing A doesn’t work because of thing B. Be ready to defend it with facts. When it comes to asking questions, don’t assume that DNS is working properly, or that network cable is attached and it’s not a crossover, or everything is powered on, or………….. you get the point. 😉

4. Share what you know.

The question my mentor asked that I responded with “I just haven’t had the time” was about my involvement with the local tech community. My other excuse was “I don’t really get anything out of it.” That, of course, was also a poor response. 😉 He went on to tell the story of the birth of Bluelock. Actually, the story of how the founders of Bluelock first met. Not surprisingly, it was a small technology group.

He recommended that I make it a priority (see tip 1), but also start sharing what I know. I countered with the fact that there are EXPERTS out there who know way more than I do, and what could I possibly have to offer the community. He pointed out that everyone is a sum of their own unique experiences. No two people live exactly the same life. Whether you consider yourself an expert or not, you bring a uniqueness no one else has. Don’t be afraid to share it. You could turn out to be an expert in someone else’s eyes.

So if you’ve been on the fence about learning PowerCLI (Powershell), Ruby, or anything else, think about these principles and how they apply to you!


PowerCLI in the Cloud

If you attended the PowerCLI sessions at VMWorld, you may remember the mention of a vCloud Snapin coming soon. This will be the first Powershell snapin allowing administration of your hybrid cloud environment. Exciting, huh?

Well, prepare to get even more excited, because…

 PowerCLI 5.01 is now available, with a shiny new snapin for vCloud Director 1.5!

Check it out:

PS > Get-PowerCLIVersion
PowerCLI Version
----------------
 VMware vSphere PowerCLI 5.01
---------------
Snapin Versions
---------------
 VMware AutoDeploy PowerCLI Component 5.0
 VMware ImageBuilder PowerCLI Component 5.0
 VMware vCloud Director PowerCLI Component 1.5
 VMware License PowerCLI Component 5.0
 VMware vSphere PowerCLI Component 5.0

 

PS > Get-PSSnapin vmware.vimautomation.cloud

Name : vmware.vimautomation.cloud
PSVersion : 2.0
Description : This Windows Powershell snap-in contains This Windows Powershell for managing Cloud..

Let’s take a look at the cloud cmdlets we get in this release!


get-command -Module vmware.vimautomation.cloud | select name

Name
----
Connect-CIServer
Disconnect-CIServer
Get-Catalog
Get-CIRole
Get-CIUser
Get-CIVApp
Get-CIVAppTemplate
Get-CIView
Get-CIVM
Get-ExternalNetwork
Get-Media
Get-Org
Get-OrgNetwork
Get-OrgVdc
Get-ProviderVdc
Import-CIVApp
Import-CIVAppTemplate

There are cmdlets for both the vCloud provider admin, AND the vCloud Org admin included in this release, so whether you run vCloud Director internally, or use a public Cloud provider like Bluelock, this snapin is for you! For your convenience, I’ve highlighted the cmdlets in the list above that are available to both Org and Provider admins.

So, let’s give them a try in a hybrid environment, where I am connected to my local vSphere and a public vCloud Provider.

To connect as an Org admin, I’ll need my username, password, and Org.

Connect-CIServer -org MyOrg -User Jake -Password cloud

I’ve connected to both my internal vSphere environment, and my public cloud provider. So doing a

Get-VM

and then a Get-CIVM will list my VMs in both environments.

You’ll also may notice from the list that there are no Set-* or New-* cmdlets. Never fear though, because in the next post we’ll take a look at making some changes to our vCloud VMs with Get-CIView and the vCloud .NET SDK.

Why are you still reading this? Go download it!


My Powershell Christmas Wishlist

Dear Santa Snover,

I met you briefly following a PowerCLI session at VMworld and gave you a part of my wishlist, but didn’t want to take up your time at that point. Here is my FULL Christmas wishlist!

  1. JSON support, like XML support. To Quote Jeff: “Watch this space.”
  2. A fix for the XML <item> bug! HERE!
  3. ISE in a web browser. Heck, I would even take just the console. Something like THIS. This would kinda give cross-platform support for those who use OSX or Linux.
  4. Intellisense in ISE for cmdlets and .NET namespaces. I love ISE because it is so lightweight. All the other IDEs I have tried are too slow. All I want to do is code.
  5. REST API support. This one is kinda iffy, as I can easily use [System.Net.Webclient], but built in XML/JSON validation would be sweet, or maybe even build a PSobject from an XML/JSON namespace.
  6. Multi-threading support that doesn’t require me to load 3rd party snapins for each job. Or, more specifically, doesn’t hog memory like it’s going out of style.
That’s it. Just six requests. I can’t guarantee whether I am on your naughty or nice list (I did mention Linux…), but these sure would be swell additions.

 
 

A cool Powershell polo would be nice too.

 
 

Cheers,
Jake Robinson