Home > Blogs > VMware PowerCLI Blog > Monthly Archives: March 2013

Monthly Archives: March 2013

VDS Export/Import with PowerCLI

One of the great new features introduced in vSphere 5.1 was the ability to export and import the configuration of your vSphere Distributed Switch (VDS) and port groups to a file.

This gives you a quick restore method in case of issues or misconfigurations and also allows you to copy the entire VDS or port group configuration to a new VDS.  This feature is detailed by this VMware KB and is available via the vSphere Web Client, below you can see how we would do this via the web client:

image

Exporting the configuration with PowerCLI

With the introduction of the VDS cmdlets in PowerCLI 5.1 R2 we can also automate this process using the Export-VDSwitch and

Continue reading

PowerCLI Lab Online – Sign up now for the public beta

If you were at VMworld in 2012 you may have attended the Hands on Labs (HOL), this is normally one of the most popular areas at VMworld as it’s a time when people can use the applications they don’t currently have installed in their own environments, they can use a virtual environment to follow instructions and see how the applications really work.

One of the most popular labs at VMworld is always the PowerCLI Lab, this was no exception in 2012, every year the PowerCLI team does a great job of adding new features to the latest version of PowerCLI and this is always a great way to check those features out in a test environment.

There has always been one issue with the HOL though, once you leave VMware you say goodbye to the HOL as access was previously at the event only….. Until Now.

There is now a public beta of the HOL Online, this gives you access to a number of different HOL Online for you to take at your own leisure and sat at the comfort of your own desk.

How do I sign up?

To sign up simply go to http://hol.vmware.com and click on the link as highlighted below:

image

Once you have filled out a few questions you will need to wait for your account to be activated (I have been assured this will be fairly quick).  Once activated you will be able to click on the “VMware Hands-on Labs Online” link as above and access a number of different labs, complete with their own isolated environment and full step by step documentation to run through the lab chosen.

How do I find the PowerCLI Lab?

Once you have gained access to the HOL and signed in use the left hand menu to select “Cloud Infrastructure”

image

Now scroll down the list on the right until you see the PowerCLI Lab, then click Enroll.

image

Once you have done this the selected Lab will be added to “My Enrollments” where you will be able to click the “Start this LAB” button to launch the lab as below:

image

The LAB will now start and you will have access as seen below:

image

PowerScripting Podcast–What’s new in PowerCLI 5.1 R2

If you enjoy podcasts or have a long commute and don’t mind listening to people talk about PowerShell then I can highly recommend the PowerScripting Podcast, they have some great PowerShell information every week and if you have not listened before then you already have 219 podcasts to catch up on!

Recently I had the pleasure of being interviewed on the PowerScripting Podcast by Hal and Jonathan, we talked about what was new with PowerCLI, what was cool in the world of PowerShell and also what I would do on a trip to Mars (I know – Random!).

For more information and ways to download the podcast visit their site here: http://powerscripting.wordpress.com/2013/03/13/episode-219-alan-renouf-from-vmware-on-powercli/

For more information on what’s new in PowerCLI 5.1 R2 make sure you check out this blog post: http://blogs.vmware.com/vipowershell/2013/02/powercli-5-1-release-2-now-available.html

Retrieving vCloud Director VM Hard Disk size

I was asked recently if we were able to retrieve the disk space of a VM in vCloud Director through PowerCLI, on checking this I found that it is not currently part of the CIVM object and also there is currently no Get-HardDisk cmdlet equivalent like in the vSphere snapin.

After looking through the REST API Reference Documentation –> User Operations I found an entry for the VM VirtualHardwareSection  and specifically the disks which can be found as can be seen here: GET /vApp/{id}/virtualHardwareSection/disks

The virtualhardwaresection is easily accessed via PowerCLI using the extensiondata property which allows access to the back end API, I could then find my disk properties by filtering on the description of Hard Disk as in the example below:

(Get-VM MyCloudVM).ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}

Now I had the hard disk I noticed that part of the information was the capacity as highlighted below:image

With this information I could then find the capacity of the disk and add the information I needed into more of a friendly PowerShell property to the Hard Disk object.

So tying this all back together we could easily use the .ExtensionData reference to create our own Advanced PowerShell function to return the hard disk information for any CIVM.

Example

The following shows an example of how to use this new function and the output, this of course can also be used to export into CSV/HTML/Text or any other format PowerShell can be used with, it is also great for reporting on where the disk space in your cloud is being used!

image

The Code

Function Get-CIVMHardDisk {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
$CIVM
)
Process {
$AllHDD = $CIVM.ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}
$HDInfo = @()
Foreach ($HD in $AllHDD) {
$HD | Add-Member -MemberType NoteProperty -Name “Capacity” -Value $HD.HostResource[0].AnyAttr[0].”#text”
$HD | Add-Member -MemberType NoteProperty -Name “VMName” -Value $CIVM.Name
$HDInfo += $HD
}
$HDInfo
}

}

Back to Basics: Connecting to vCenter or a vSphere Host

Following my previous post which took you through the install of PowerCLI I thought it was time to add another back to basics (B2B) post and show how to take the first step in using PowerCLI… Connecting to your vCenter or vSphere host.

Yes, PowerCLI can be used to connect to both vCenter and also the vSphere host independently, of course not all the cmdlets will be relevant if you connect to just the host but still, this can be useful during the initial setup or automated deployments of the complete infrastructure.

How to connect

If you are connecting to either a vCenter server or a vSphere Host the cmdlet is the same, you can use the Connect-VIServer cmdlet to connect to both of these (even at the same time), lets take a look at an example:

C:\PS>Connect-VIServer -Server vcenter01 -User admin -Password pass

In the above example you can see we are connecting to our vCenter server called “vcenter01” with a username and password to gain access to the vCenter server, we did not specify a protocol or port, by default HTTPS and port 443 is assumed which is the same as the vSphere Client or Web Client, unless you specify a –port or –protocol parameter for the cmdlet.

Credentials

In the example above we used the –User and –Password parameters to pass through the credentials but this might not always be what you want to do, especially as PowerShell files are plain text!  There are multiple ways in which we can specify the credentials or store the credentials, its really up to you which you use and which is best suited for your situation.

Continue reading