Building More PowerCLI Custom Functions for SRM, Step by Step Walkthrough

One of my colleagues Ken Werneburg recently wrote a great blog post about executing an SRM failover via PowerCLI. Ken does a great job of explaining some of the caveats around this feature and how you would actually make the call using PowerCLI. Looking at the code provided I thought it would be a good candidate for encapsulating in a custom function. I wrote recently about using custom functions to simplify using the SRM API from PowerCLI and I think this use case would be a great example.

In Ken’s example he is coding against the raw API from PowerCLI and you have to deal with code like this:

$RPmoref = … # Set the recovery plan we want to use

# define the recovery plan mode we want to use ('1' is a test)
$RPmode = New-Object VMware.VimAutomation.Srm.Views.SrmRecoveryPlanRecoveryMode
$RPmode.Value__ = 1

# start the test
$RPmoref.Start($RPmode)

While this is not too hard to follow it does require that the user to create recovery mode objects using “magic” numbers in the code. Using custom functions we can hide that away and deliver something much nicer. What I would like us to get to is something like:

Start-RecoveryPlan -RecoveryPlan $Plan -RecoveryMode Test

Or even:

Get-RecoveryPlan -Name 'Failover Site A' | Start-RecoveryPlan

So, how do we get there?

First let’s determine how we want to be able to call the functions and specify the parameters we will accept. Here’s my first crack at this:

<#
.SYNOPSIS
Start a Recovery Plan action like test, recovery, cleanup, etc.

.PARAMETER RecoveryPlan
The recovery plan to start

.PARAMETER RecoveryMode
The recovery mode to invoke on the plan. May be one of "test" (the default), "recovery", "cleanup", and "reprotect"
#>
Function Start-RecoveryPlan () {
    Param(
        [Parameter (Mandatory=$true, ValueFromPipeline=$true)] $RecoveryPlan,
        [VMware.VimAutomation.Srm.Views.SrmRecoveryPlanRecoveryMode] $RecoveryMode = 'Test'
    )

    #TODO
}

<#
.SYNOPSIS
Stop a running Recovery Plan action.

.PARAMETER RecoveryPlan
The recovery plan to stop
#>
Function Stop-RecoveryPlan () {
    Param(
        [Parameter (Mandatory=$true, ValueFromPipeline=$true)] $RecoveryPlan
    )

    #TODO
}

A couple of things to note here. First we can directly use the SrmRecoveryPlanRecoveryMode type when defining the parameter. The PowerCLI team have made this an enum type so we get some nice behavior out of the box in terms of type casting. The second thing to note is that we are going to default to a ‘Test’ operation. I am doing this as I don’t want to get into the scenario where we default to a recovery and someone initiates a disruptive failover instead of a test or cleanup, simply because of a scripting error.

Now we have the outline of the functions let’s try and fill them in a little. First we’ll look at the Start-RecoveryPlan function. For this we want to be able to take in the recovery plan and mode parameters and call the SRM API with that information, maybe with a bit of error checking in there as well. If we take the example from Ken’s blog and put it into our function we should get something like:

Function Start-RecoveryPlan () {
    Param(
        [Parameter (Mandatory=$true, ValueFromPipeline=$true)] $RecoveryPlan,
        [VMware.VimAutomation.Srm.Views.SrmRecoveryPlanRecoveryMode] $RecoveryMode = 'Test'
    )

    # Validate with informative error messages
    $rpinfo = $RecoveryPlan.GetInfo()

    if ($rpinfo.State -eq 'Protecting') {
        throw "This recovery plan action needs to be initiated from the other SRM instance"
    }

    $RecoveryPlan.Start($RecoveryMode)
}

The only real change we have made is to avoid tripping ourselves up by running the recovery plan from the protected site. The API expects the plan to be run from the recovery site so we add a check to ensure the recovery plan state is not in the 'Protecting' state which is the default state a plan is in when seen from the protected site API.

Given that executing a recovery plan could be a disruptive event it makes sense to prompt the user for confirmation before executing the failover. We can do this by annotating our cmdlet with SupportsShouldProcess=$True and checking the value of $pscmdlet.ShouldProcess in our function.

So for one final time let’s put it together for our Start-RecoveryPlan function:

Function Start-RecoveryPlan () {
    [cmdletbinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter (Mandatory=$true, ValueFromPipeline=$true)] $RecoveryPlan,
        [VMware.VimAutomation.Srm.Views.SrmRecoveryPlanRecoveryMode] $RecoveryMode = 'Test'
    )

    # Validate with informative error messages
    $rpinfo = $RecoveryPlan.GetInfo()

    # Prompt the user to confirm they want to execute the action
    if ($pscmdlet.ShouldProcess($rpinfo.Name, $RecoveryMode)) {
        if ($rpinfo.State -eq 'Protecting') {
            throw "This recovery plan action needs to be initiated from the other SRM instance"
        }

        $RecoveryPlan.Start($RecoveryMode)
    }
}

We can do similar updates for the corresponding Stop-RecoveryPlan function as well. When we put them together with some of the custom functions we have defined earlier it makes it fairly easy to put together very concise scripts like this:

# First let's connect to VC and both SRM servers
$localvc = …
$un = …
$pw = …
Connect-VIServer -Server $localvc -User $un -Password $pw
Connect-SrmServer -User $un -Password $pw -RemoteUser $un -RemotePassword $pw

#Then let's find a recovery plan and execute a failover

Get-RecoveryPlan -Name '_Manchester Site Failover' | Start-RecoveryPlan -RecoveryMode Failover

As always a picture (or in this case a video) can say a thousand words…

I’ve also shared these functions in my SRM Cmdlets github repository to make it easier to illustrate how you can develop this. As always I’ll reiterate that I am pretty new to PowerShell so if you have any feedback, especially on the scripting style say, please let me know!

Design Crazy?

One of the perks of traveling for business is the time I get to catch up on some reading while flying between locations. Last week I had the chance to travel to Missouri to visit some customers and was able to reread a couple of books I’ve found interesting. The one I want to write about now is an interesting look at Apple’s approach to selecting, designing, and bringing products to market. The book, Design Crazy, is very short and a quick read, it is really a large collection of quotes from people involved in the work arranged around certain themes and events.

Here are a few of the items I highlighted while reading:

“The competitors, like Commodore and Kaypro, were all doing speeds and feeds, whereas Steve always wanted things like “What is the significance in the world? How might this change things?” – Steve Hayden

 

“He was thinking about the problem very holistically, saying, “Can we unify this experience?” – Don Lindsay

 

“The challenge in delivering simplicity is, marketing wants to bring more functionality to bear, engineering wants to bring more options to bear—and all of that just adds to confusion and clutter.” – Don Lindsay

 

“Jony’s funny. He’s an artist, which made him very different from the engineers. We would have arguments about stuff, but the best products come when there’s creative tension.” – Jon Rubinstein

 

“The compromises Apple took on design were legendary: you didn’t have copy/paste, you didn’t have multi-tasking, you didn’t have apps. Apple said, “We just want to have a cool phone.” They focused on making people love the product. And that’s the distinction at the end of the day. Everybody else was focusing on being smart. Apple focused on being loved.” – Horace Dediu

 

“There had always been products that had been beautifully designed. But they were high-end, and very few people actually owned them. Apple was the first company that took high design and made it mainstream. It taught the world taste.” – Phil Libin

The author, Max Chafkin, uses selection and organization of the quotes to share the story rather than trying to clumsily imposing a more explicit narrative on top.

SRM, PowerCLI, and custom functions

One of the important benefits of the new PowerCLI release is that it exposes SRM’s public API in a relatively easy to consume manner. Having said that calling SRM API methods directly via PowerCLI is not exactly idiomatic. Here’s the example from the PowerCLI user guide on how to protect a VM.

# Connect to the vCenter Server system that the SRM server is registered with.
 Connect-VIServer -Server vc3.example.com -User 'MyAdministratorUser' -Password 'MyPassword'

 # Establish a connection to the local SRM server by providing credentials to the remote SRM site.
 $srm = Connect-SrmServer -RemoteUser 'MyRemoteUser' -RemotePassword 'MyRemotePassword'

 # List all protection groups associated with the SRM server.
 $srmApi = $srm.ExtensionData
 $protectionGroups = $srmApi.Protection.ListProtectionGroups()

 # Associate the TestVM virtual machine with the ProtGroup1 protection group and enable the protection for that virtual machine.
 $vmToAdd = Get-VM "TestVM"
 $targetProtectionGroup = $protectionGroups | where {$_.GetInfo().Name -eq "ProtGroup1" }
 $targetProtectionGroup.AssociateVms(@($vmToAdd.ExtensionData.MoRef)) # VR specific call

 # Enable protection for that virtual machine
 $protectionSpec = New-Object VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionSpec
 $protectionSpec.Vm = $vmToAdd.ExtensionData.MoRef
 $protectTask = $targetProtectionGroup.ProtectVms($protectionSpec)
 while(-not $protectTask.IsComplete()) { sleep -Seconds 1 }

While the code is reasonably straightforward to follow along it doesn’t follow the PowerShell style and we can certainly try and simplify it.

What I am going to show is how you can create custom functions that make it easier to hide this complexity when you are trying to get stuff done. For example how about we replace all that API wrangling with a couple of custom functions? Something like this perhaps:

# Connect to the vCenter Server system that the SRM server is registered with.
 Connect-VIServer -Server vc3.example.com -User 'MyAdministratorUser' -Password 'MyPassword'

 # Establish a connection to the local SRM server by providing credentials to the remote SRM site.
 Connect-SrmServer -RemoteUser 'MyRemoteUser' -RemotePassword 'MyRemotePassword'

 # Find the protection group
 $pg = Get-ProtectionGroup -Name 'ProtGroup1'

 # Protect the Virtual Machine
 Get-VM -Name 'TestVM' | Protect-VM -ProtectionGroup $pg

In this example we’ve reduced 11 lines of API heavy code into 4 fairly simple lines by creating a couple of custom functions Get-ProtectionGroup and Protect-VM. These custom functions enable us to hide the complexity of calling the API directly. Here’s a quick video demonstrating this in action.

But we don’t have to stop there! SRM’s API exposes a lot of operations so there is plenty to automate. Let’s say you wanted a list of Virtual Machines that are included in a recovery plan, with custom functions this could be as easy as chaining together cmdlets to retrieve the recovery plan, find any associated protection groups and then the retrieve the VMs associated with those groups, e.g.:

Get-RecoveryPlan -Name 'Failover Site A' | Get-ProtectionGroup | Get-ProtectedVm

…much simpler than having to call into the SRM API directly!

I’ve got very limited experience with PowerCLI but it wasn’t too difficult for me to knock up a few PowerCLI functions to do this. I’ve shared my SRM custom functions on Github (for illustrative purposes) and it has certainly proven useful for me. Hopefully there are some PowerCLI gurus out there and the community who can fix all the obvious mistakes I’ve no doubt made and share something better with the community!

Please share your feedback and let me know what kind of SRM operations you’d like to be able to automate and why.

SRM, PowerCLI, and some imagination

One of the things I really enjoy about being a Product Manager for VMware’s Site Recovery Manager is listening to people tell their stories. It’s always great to hear how customers have increased capacity to cope with disasters through the improved recovery orchestration and non-disruptive testing SRM offers them. As well as listening to customers celebrate their successes, being a Product Manager is about digging deep into the customers experience to understand the sources of any frustrations and identify areas where we can further improve.

One area I know that is of interest to SRM customers is increasing the automation around SRM itself. For example: being able to query SRM to see what is being protected (and what isn’t); kicking off recovery plan tests; and automatically protecting virtual machines with SRM during provisioning. Knowing this I was really pleased to hear that the PowerCLI team were working on some SRM cmdlets and, with PowerCLI 5.5 R2, that team has delivered!

My colleague Ken Werneburg wrote up a good overview of the cmdlets with some useful links and during the recent #vBrownBag Alan Renouf gave a great intro as well as a live demo (see video below).

And We’re Full!

I was checking the attendance number for my VMworld 2013 session today and realized it was completely full! Now that’s intimidating.

Preparing for the session has certainly been taking up a lot more of my time than I originally envisioned. The session is BCO5652 – Three Quirky Ways to Simplify DR with Site Recovery Manager and I am definitely planning on erring towards the more technical content. One drawback to this kind of presentation is that there is always way to much information to fit into a single presentation. A corresponding advantage however is that I have some material for the next few blog posts after VMworld!

VMworld 2013

In 2012 I attended VMworld for the first time. I managed to sneak in a breakout session or two amongst a multitude of customer briefings and prowling the Expo floor to see some of the shiny new things from the ecosystem. It was certainly an exciting event and a great introduction to the excitement and passion surrounding VMware. One of the few downsides to last years events was that I missed a lot of the after-hours activities due to the commute back to San Jose every evening.

Well it’s 2013 now and VMworld is rolling around again. This year I am lucky enough to be presenting a session, BCO5652 – Three Quirky Ways to Simplify DR with Site Recovery Manager. Also I will be taking advantage of San Francisco’s hotels and staying in the city during the conference so I can be closer to the action this year.

B2B and Social Media

For my Social Media class I was asked to read an article by Valeria Maltoni called The Truth About B2B Social Media Adoption. The article covers the frustrations that many business experience:

The truth about social media adoption… is that many B2B (business to business) marketers are frustrated and less than satisfied with the performance of their website, social, search marketing and sales conversion efforts. This is especially true in small and mid-sized companies…

Valeria’s article references a survey by Penton Marketing Services that reveals a majority of B2B companies are dissatisfied with the performance of their website in meeting their companies goals: It doesn’t deliver enough leads, doesn’t effectively support customer service etc. Given this fairly poor base it is easy to see why many small to mid-sized businesses are loathe to invest much money or effort in social media.

Determining the Social Media Marketing Mix

Companies that are investing in online marketing need to determine what marketing mix to use, for many businesses it is invested in those channels that have an easily measured impact on the business. Justifying marketing spend on vanity metrics like likes or re-tweets is getting increasingly trickier, tying the impact of social channels into metrics that reflect desired business goals is increasingly important. Ensuring these links are correctly attributing the impact of social media is important, Adobe recently published a report that shows that common methods of attributing the impact of social media can underestimate the impact by up to 94%.

On social media adoption Valeria writes that:

Among those who have social media outposts, Facebook, at 90 percent, is by far the most widely used networks, followed by Twitter at 53 percent, and LinkedIn at 47 percent.

B2B companies are mainly adopting the Hub and Spoke organization for their online properties. Companies can be seen to be using different social media channels for fairly different reasons:

Purpose/Channel Blogs Facebook Twitter LinkedIn Youtube
Customer Service X
Product Marketing X X X
Brand Marketing X X
Company News X X X
Industry News X
Recruiting X X

Some channels are better suited to communicating certain messages. For example the professional focus of LinkedIn has made it a favored channel for recruitment, meanwhile YouTube is often used to provide additional product information or general brand promotion.

Impact of the Right Content Strategy

It is important to ensure that the right channel is delivering appropriate content that supports the business goal. Delivering effective online content and promoting it can dramatically lower the cost of generating new leads. Hubspot have estimated that inbound marketing costs about 62% less than outbound marketing per lead.

What is a content strategy and how do you know you’ve got it right? One of my favorite definitions of content strategy is:

Content strategy plans for the creation, publication, and governance of useful, usable content. Necessarily, the content strategist must work to define not only which content will be published, but why we’re publishing it in the first place. Otherwise, content strategy isn’t strategy at all: it’s just a glorified production line for content nobody really needs or wants. (See: your company’s CMS.)

Kristina Halvorson

If we know why we are publishing something we should be able to tie that into a measurable metric, whether it’s cheaper leads, increased order sizes, shorter sales cycles etc. At the end of the day to show an ROI we need to either show we are either making money or saving money by investing in this pushing content to our channels.

Engage Intelligently

In her post Valeria makes the point that B2B organizations where many subject matter experts reside. If we want to effectively reach them we need to communicate using smart and engaging content.

If we can deliver this we can be influencers within our target industries so that when those organizations are early in their procurement life cycle we are top of mind.

Does Emotional Advertising Work For Businesses?

In my earlier post discussing emotions in advertising I made the point that advertising that connects with us emotionally is more effective than advertising that promotes product features”. This is a fairly accepted point but how true is it? For some campaigns, such as UK Cancer Research, the use of powerful emotional appeals is congruent with the subject matter. However how does this work for Businesses looking to make emotional connections? Coming on too strong would no doubt turn consumers off.

For me Dove’s campaign for real beauty is a great example of a brand that was able to successfully make a powerful emotional connection.

By transitioning their messaging away from the typical features and benefits to a more emotional level Dove’s brand became much more differentiated. This emotional connection ensures customers have a higher recall of the advert and impacted their purchase behavior. These effects have been observed in a variety of advertising.

The ads that performed well on the traditional system two measures (persuasion, cut-through, brand linkage, message delivery) were actually less effective in market than the nine ads performing poorly on these measures. In fact, designing the advertising to perform well on such measures may work against effectiveness. Meanwhile, the nine most emotional ads delivered greater business effects than the nine least emotional ads.
Let’s get emotional about ads

For businesses making a strong emotional appeal can move the needle, if it is congruent with their brand. So should we neglect rational adverts? Research suggests that actually a balanced approach works best. Emotional adverts tend to outperform purely rational adverts, but a combination of emotional advertising that clearly communicates rational benefits performs best.