I read on Technet that Microsoft recommend to use service templates in VMM 2012 even for a single server. Instead of using a VM template we should use a service template to deploy a new virtual machine. In Orchestrator there is an activity in the Virtual Machine Manager (VMM) integration pack that can create a new virtual machine from a template. But there is no activity to create a new instance from a service template. So I copy/paste “wrote” a script that deploys a new instance of a service, based on a service template. This is a very basic and simple example script that you can use as a foundation. The script will ask for five input parameters
- CloudName = Target cloud in VMM for the new service
- SvcName = Name of the new service. As I only deploy a single server I use the computer name as service name too
- ComputerANDvmName = The name that will be used both for the virtual machine and the computer name
- SvcTemplateName = The service template to use
- Description = A description that will be added to the new service instance
Param(
[parameter(Mandatory=$true)]
$CloudName,
[parameter(Mandatory=$true)]
$SvcName,
[parameter(Mandatory=$true)]
$ComputerANDvmName,
[parameter(Mandatory=$true)]
$SvcTemplateName,
[parameter(Mandatory=$true)]
$Description)
Import-Module ‘C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\virtualmachinemanager\virtualmachinemanager.psd1’$cloud = Get-SCCloud -Name $CloudName
$SvcTemplate = get-scServicetemplate -Name $SvcTemplateName
$SvcConfig = New-SCServiceConfiguration -ServiceTemplate $SvcTemplate -Name $SvcName -Cloud $cloud -Description $Description
$WinSrvtierConfig = Get-SCComputerTierConfiguration -ServiceConfiguration $SvcConfig | where { $_.name -like “Windows*” }
$vmConfig = Get-SCVMConfiguration -ComputerTierConfiguration $WinSrvtierConfig
Set-SCVMConfiguration -VMConfiguration $VMConfig -name $ComputerANDvmName -computername $ComputerANDvmName
Update-SCserviceConfiguration -ServiceConfiguration $Svcconfig
$newSvcInstance = New-SCService -ServiceConfiguration $Svcconfig
The script first create and configure a service deployment configuration. The service deployment configuration is an object that is stored in the VMM Library that describes the new service instance, but it is not running. The last two lines in the script will pick up that service deployment configuration and deploy it to. All settings of the new service instance is stored in the service deployment configuration. In my service template, named “Contoso Small”, I have a tier named “Windows Server 2008R2 Enterprise – Machine Tier 1” that is why the script search for a tier with a name like “Windows*”.
When we have a PowerShell script we can easy use it from a runbook in Orchestrator to deploy new instances of services.
Note that the script is provided “AS-IS†with no warranties.
Thanks for sharing your knowledge Graham, I agree with you that deploying Everything as a service could make things a bit messy.
“I read on Technet that Microsoft recommend to use service templates in VMM 2012 even for a single server.”
Personally, I’d be careful with that approach. Creating a Service Template in VMM 2012 creates a Distributed Application in SCOM and a Busines Service in SCSM for a service that doesn’t actually exist.
It also ties back every single virtual machine created from that template back to the original service. Anyone doing this needs to be aware of the implications of then updating that Service Template.
If administrators just want to deploy a single machine then I’d strongly consider use a mix of the standard VMM template and leveraging Orchestrator to add the required roles and features.
You mean adding a existing VM to a service?
How to create a service in VMM existing VM.
Very nice article that should minimize the “resistance” to using Orchestrator. Thanks for a practical introduction to the subject.