The DPM team recently posted a blog article that provided PowerShell scripts on automatically protecting new virtual machines in Hyper-V, original article at http://blogs.technet.com/dpm/archive/2009/12/03/hyper-v-protection-with-dpm-2010-beta-how-to-automatically-protect-new-virtual-machines.aspx. Basically there are two scripts but both essentially do the same thing, when run they look for any unprotected virtual machines and protects them, the only difference is that one is for clustered Hyper-V hosts and one is for stand alone Hyper-V hosts. Both scripts do exactly what they say they do except it's still not automatic, you still need to manually run the script and this gave me an idea, why not get Operations Manager to run the script?
Thinking about it further there are loads of ways to use the script in Operations Manager, we could create a manual task that runs the script, we could create a timed script rule to automatically run it on a scheduled basis or if you were so inclined you could create a monitor that checked for unprotected virtual machines and then run the PowerShell script as an automatic recovery action if any were found.
I am going to demonstrate how to create a timed script rule to run this script as I actually had to do it in my test environment as I have new virtual machines appearing and disappearing daily. The automatically protect new VMs scripts are designed to work on DPM 2010 only and you'll need to be running Operations Manager 2007 R2. You will also need the Operations Manager Authoring Console to be able to do this.
So with the Authoring Console open, let's make a start by creating a new management pack by going File -> New... . Select the Empty Management Pack option and provide an ID.

Provide a friendly name and description for the management pack, click Create and save the management pack.
As we will want to target the rule at a DPM protected computer we need to add the Microsoft DPM MP as a reference. From the File menu select Management Pack Properties, select the References tab and click Add Reference... . Navigate the Microsoft.Windows.SystemCenterDPM.mp management pack file and add it as a reference. When the new MP reference has been added, click OK and save your management pack.

Now select the Health Model pane and click on Rules in the Health Model tree. From the Actions menu select New -> Custom Rule... and provide a unique ID for the new rule.

Provide a friendly name and description for the rule and set the target to Microsoft.Windows.SystemCenterDPM.ProductionServer.

Select the Modules tab and click Create under Data Sources. Highlight the System.Scheduler module and enter a module ID, then OK.

Highlight your new data source and click Edit and then click Configure. Set your schedule and OK your way out.

With the data source now done, click the Create button under Actions. Select the Microsoft.Windows.PowerShellWriteAction module and give it a unique ID then hit OK.

With the Script module highlighted, click Edit and then click Edit again. Enter a name for the script, the script itself and a timeout value in the relevant XML tags. For the script, I have literally just taken the stand alone script given on the Ctrl-P blog and cut it down a bit, so I have removed all the lines which write to the host as these are not necessary. I have also specified the production server name and protection group name in the script as this rule will only run against one Hyper-V host. Download my modified script here, all you need to do is update the production server name and protection group name if you want to use it. Once done, OK back to the Modules tab.

Click Apply at this point to make sure you don't loose any work.
Now select the Options tab and change the category to Operations and Enabled to false as we only want this rule to run on a selected Hyper-V server. Note: After the management pack is imported, simply create an override to enable the rule for the production server you specified in the script.

Click OK, save your MP and import it into Operations Manager. Done !
Well nearly done, as the rule is in a non-enabled state you will need to create an override to enable for the Hyper-V host production server you specified in the script. You will have to save this override into the same management pack unless you decide to seal it.
If you would like to set this up as a task in Operations Manager you can do that to as you can pass the production server name and protection group name to the script in the task. If you would like to do this, use my Creating DPM PowerShell Tasks in DPM article as a base.
Hope you enjoy bringing these to System Center products closer together. 
|
David Allen
MVP System Center Operations Manager
|