Tag Archives: PowerCLI

My VMworld 2013 Sessions

image_thumb1This year there are some awesome sessions at VMworld, I think people are starting to realize the benefits of automation and how these can be achieved with VMware products.  I am looking forward to attending and hopefully presenting some great sessions at VMworld 2013.

Today is the last day of voting so if you are still looking through the session list and wondered what I had put forward this year then please find a list below, if these looks interesting to you then please feel free to vote for it here!

Continue reading →

Gathering simple pool information from VMware View

Recently I was asked if we could list some basic information from VMware View using the cmdlets which come installed on the View Administrator server, the request was specifically a list of VMs and the pool they were in, this was easily achieved with the Get-DesktopVM cmdlet as below:

Get-DesktopVM | Select Name, Pool_id | Sort Pool_id

Continue reading →

Automating storage with NetApp Workflow Automation

Do you wish you could automate your NetApp Storage infrastructure?

Do you wish your storage admins could give an easy to use custom interface to other areas of the business allowing them to provision or use storage however they need whilst still applying best practice and corporate policies to the configuration?

Continue reading →

Relating vCloud Director to vCenter in PowerCLI

I was listening to episode 216 of the PowerScripting Podcast recently, Hal and Jonathan were talking to vCloud Director (vCD) expert Jake Robinson and “meeting expert” (listen it will make sense) Damian Karlson, it was a great show, very funny and I highly recommend you listen here: http://powerscripting.wordpress.com/2013/02/26/episode-216-jake-robinson-and-damian-karlson-talk-powercli/

Anyway, they were talking about relating vCD objects to vCenter objects, on the show they said it couldn’t be done without matching an ID and writing a custom function, this used to be the case but now I wanted to show a few cool things from PowerCLI which allows us to use a parameter called –RelatedObject to take away all the hard work from the matching IDs, Datastore IDs, Network IDs etc. Continue reading →

PowerCLI 5.1 R2 Released

PowerCLIVersionVMware have just released PowerCLI 5.1 R2 and with it are the long awaiting cmdlets to work with VDS!

I worked with these a little and although VDS are not 100% fully covered in this release the cmdlets are certainly useful for most of the things I needed to do and they opened up VDS with the .extensiondata property for the rest of the things I wanted to play with.

Two of the cooler cmdlets where the Export-VDSwitch and New-VDSwitch –backupfile which can be used with 5.1 and the new VDS features to backup the VDS into a simple zip file and re-import it when needed.

I have included the new cmdlets and some examples from the help file below.

As well as the VDS cmdlets I am also happy that VMware now supports PowerShell v3 and vCloud Director 5.1 in both their admin version of PowerCLI and their Tenant version, this opens up vCD to automate some of the cooler new features of VCD and also enable the enhancements made by Microsoft in PowerShell v3.

Download it now. Continue reading →

Learning PowerCLI–What does it take ?

One of the most asked questions to me at VMworld this year was “what does it take to learn PowerCLI”, lots of people have seen the fantastic things you can do with PowerCLI, where it is drawing your infrastructure out into Visio or checking your VMware environment for potential issues.

I always tell people that if I can learn PowerCLI then anyone can, one of the great strengths of PowerCLI and PowerShell is that it was written for System Administrators, for the people who need to get the job done, get it done fast and move on to the next thing.

With that in mind it is not only easy to understand what something like New-VM does but also very easy to learn as all the information you need is often very easy to read, easy to work out what’s going on and also right there in the PowerCLI console.

One of my favorite learning resources is the help built in to PowerCLI.

From within the console you can easily access not only the full help for each cmdlet but also examples of how you might use this cmdlet, these are great because they not only show examples of how to use the cmdlets but also cover some of the top use cases for that cmdlet.  A great deal of thought goes into the help files and these examples to make them relevant and useful.

To access the help and the examples for a cmdlet there are multiple ways, firstly you can see the help as part of the online documentation for PowerCLI here, secondly you can run the Get-Help cmdlet and also use the –examples parameter to gain more information, see below for an example:

PowerCLI Example

I still don’t understand what it takes to learn PowerCLI ?!

If you still don’t get it and need a full on action video with cool music and stunts to get this simple feature then check out the below:

What does it take to learn PowerCLI ? from Alan Renouf on Vimeo.

Using PowerShell v3.0 CIM cmdlets with VMware ESXi Hosts

I noticed that in PowerShell V3.0 some CIM cmdlets were introduced which allowed PowerShell to be able to interact with CIM providers and gather information, when importing the CIM Cmdlets into my session you can see we have a number of new cmdlets to work with:

image

Even though I know PowerCLI 5.1 R1 (Current release on 29th Oct 2012) does not support PowerShell v3.0 I thought I would check out what I could do with these and what information I could receive using the CIM cmdlets.

As a reminder, Carter Shanklin did some work in this area a long time ago and he ended up writing a function to be able to pull CIM information from ESX hosts, this can be found here, he also includes some links to documentation on the CIM providers the VMware hosts can provide: http://blogs.vmware.com/vipowershell/2009/03/monitoring-esx-hardware-with-powershell.html

As you will see from the video below the new cmdlets cut out most of the hard work Carter had to do and allow us to pull CIM information from the ESXi hosts with ease.

Using PowerShell v3.0 CIM Cmdlets with VMware ESXi Hosts from Alan Renouf on Vimeo.

For your reference, here is the code I used during this demo:

import-module CimCmdlets
$ipaddress = "10.20.177.15"
$HostUsername = "root"
$CIOpt = New-CimSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -Encoding Utf8 -UseSsl
$Session = New-CimSession -Authentication Basic -Credential $HostUsername -ComputerName $Ipaddress -port 443 -SessionOption $CIOpt
Get-CimInstance -CimSession $Session -ClassName CIM_Fan

vMotion and SvMotion Details with PowerCLI

Today I was asked if there was a way to list the vMotions and SvMotions which had occurred in an infrastructure, not only this but they needed to know which hosts the VMs had moved to, the reason for this was licensing.

Firstly they needed to confirm that certain VMs were firstly setup with DRSAffinityrules as disabled, this one was straight forward in PowerCLI:

Get-VM | Select Name, DRSAutomationLevel

image

Secondly they wanted a list of the vMotions and SvMotions which had taken place over the last week and specifically the source and destination hosts, a post on the VMware PowerCLI Blog gives us most of this information and was easy to adjust to include the source and destination hosts…

image

The adjusted script can be found below:

Function Get-MotionDuration {
    $events = Get-VIEvent -Start (Get-Date).AddDays(-7)
    $relocates = $events |
        where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.migrate" -or $_.Info.DescriptionId -eq "VirtualMachine.relocate"}
    foreach($task in $relocates){
        $tEvents = $events | where {$_.ChainId -eq $task.ChainId} |
            Sort-Object -Property CreatedTime
        if($tEvents.Count){
            New-Object PSObject -Property @{
                Name = $tEvents[0].Vm.Name
                Type = &{if($tEvents[0].Host.Name -eq $tEvents[-1].Host.Name){"svMotion"}else{"vMotion"}}
                StartTime = $tEvents[0].CreatedTime
                EndTime = $tEvents[-1].CreatedTime
                Duration = New-TimeSpan -Start $tEvents[0].CreatedTime -End $tEvents[-1].CreatedTime
				SourceHost = $tEvents[0].Host.Name
				DestinationHost = $tEvents[-1].Host.Name
            }
        }
    }
}


Connect-VIServer MyViServer –User Administrator –Password “Pa$$w0rd”

Get-MotionDuration | FT -AutoSize

Quick Host Profile Reports

Today I needed to grab some quick information on my hosts, which hosts had host profiles enabled, if they were compliant and if not what where the issues ?

With the below script I was easily able to grab this information, as can be seen in the screenshot below:

image

The Script

$HPDetails = @()
Foreach ($VMHost in Get-VMHost) {
	$HostProfile = $VMHost | Get-VMHostProfile
	if ($VMHost | Get-VMHostProfile) {
		$HP = $VMHost | Test-VMHostProfileCompliance
		If ($HP.ExtensionData.ComplianceStatus -eq "nonCompliant") {
			Foreach ($issue in ($HP.IncomplianceElementList)) {
				$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
				$Details.VMHost = $VMHost.Name
				$Details.Compliance = $HP.ExtensionData.ComplianceStatus
				$Details.HostProfile = $HP.VMHostProfile
				$Details.IncomplianceDescription = $Issue.Description
				$HPDetails += $Details
			}
		} Else {
			$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
			$Details.VMHost = $VMHost.Name
			$Details.Compliance = "Compliant"
			$Details.HostProfile = $HostProfile.Name
			$Details.IncomplianceDescription = ""
			$HPDetails += $Details
		}
	} Else {
		$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
		$Details.VMHost = $VMHost.Name
		$Details.Compliance = "No profile attached"
		$Details.HostProfile = ""
		$Details.IncomplianceDescription = ""
		$HPDetails += $Details
	}
}
$HPDetails

VMworld 2012 Barcelona

I have high hopes for VMworld Barcelona, personally I had a great, if not busy time at VMworld 2012 SFO and hope to continue this in true European style in Barcelona.

I wanted to just highlight what my main plans were as one of the things that always makes VMworld for me is talking to people about what they are doing and specifically how they are using or would like to use PowerCLI or automation in general.

So, if you are attending VMworld Barcelona then please do come see me and we can have a chat.

My Schedule

EXPERTS04 – Meet the Experts – 04

Tuesday, Oct 9, 5:00 PM – 6:00 PM

Stop by the Meet the Experts Lounge to book time with a Knowledge Expert. They are available throughout the week for casual, one-to-few discussions. Please reference their availability now and stop by the Lounge reception desk in Hall 6, to schedule a 30-minute appointment.

GD33 – PowerCLI with Alan Renouf

Wednesday, Oct 10, 11:00 AM – 12:00 PM

Join me in this Group Discussion on PowerCLI and automation, I loved these in SFO hearing what people were doing and the challenges people had, come have your say ! (Book early it fills fast)

INF-VSP1252 – What’s New with vSphere 5.1 – ESXCLI & PowerCLI

Wednesday, Oct 10, 5:00 PM – 6:00 PM

Thursday, Oct 11, 1:30 PM – 2:30 PM

In this session Technical Marketing automation experts William Lam and Alan Renouf will take you through What’s New in ESXCLI and PowerCLI for the vSphere 5.1 release. In this session Alan and William will take you through the exciting features available to use when automating VMware products, both beginners and experts will learn how to use new features to make your life easier and more productive.

INF-VSP1329 – PowerCLI Best Practices: The Return!

Tuesday, Oct 9, 2:00 PM – 3:00 PM

Thursday, Oct 11, 9:00 AM – 10:00 AM

Building on the success of our PowerCLI Best Practices sessions from VMworld 2011, we want to show you our next collection of PowerCLI best practices. This session will show and demonstrate PowerCLI in all its aspects managing and automating not just VMware vSphere® but also VMware vCloud Director®, VMware® View™, VMware vShield™ and more.  Presenting with the awesome Luc Dekens.