Export a Package from a VMM Server and Import It to a Dissimilar VMM Server by Using Advanced Mapping (Script)

 

Updated: May 13, 2016

Applies To: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

You can share service templates between dissimilar VMM management servers by exporting the template from one VMM management server, creating a package mapping that redirects resources from the imported template to the resources in the target environment, and then importing the template package.

Note

The script in this topic assumes that you have saved the function from Create a Function that Exports a Package (Script) with the name Export-ServiceTemplate.ps1.

Disclaimer

The following script loads and uses the function named Export-ServiceTemplate.ps1 to export the specified template. It then creates a package mapping and imports the template to a VMM management server that is different from the one from which the template was exported, using the package mapping to redirect the resources.

<#  
  Description:   This script calls a function to export a service template, then  
                 creates a package mapping to map a Run As account and a logical   
                 network to the resources on the target server. The script then   
                 restores the specified template to the dissimilar VMM management   
                 server.  
#>  
  
Param (  
   [parameter(Mandatory=$true)]  
   [String] $ServiceTemplate=$(throw "Please provide the name of a service template."),  
  
   [parameter(Mandatory=$true)]  
   [String] $Release=$(throw "Please provide a release for the service template."),  
  
   [parameter(Mandatory=$true)]  
   [String] $Path=$(throw "Please provide a share path."),  
  
   [parameter(Mandatory=$true)]  
   [String] $VMMServer=$(throw "Please provide the name of a VMM server.")  
   )  
  
# Import the file containing the export function into the Windows PowerShell session.  
. .\Export-ServiceTemplate.ps1  
  
# Export the service template using the Export-ServiceTemplate function.  
Export-ServiceTemplate -Name $ServiceTemplate -Release $Release -Path $Path -VMMServer $VMMServer  
  
# Get the template package.  
$RestorePath = "$Path\$ServiceTemplate.$Release.xml"  
$Package = Get-SCTemplatePackage -Path $RestorePath  
  
# Create a package mapping.   
$PackageMapping = New-SCPackageMapping -TemplatePackage $Package  
  
# Map the resources from the imported template to the resources in  
# the target environment.  
  
$Mapping = $PackageMapping | where { $_.PackageID -eq "Domain RAA" }  
$NewResource = Get-SCRunAsAccount -Name "DomainAdminRAA"  
Set-SCPackageMapping -PackageMapping $Mapping -TargetObject $NewResource  
  
$Mapping = $PackageMapping | where { $_.PackageID -eq "LogicalNetwork01" }  
$NewResource = Get-SCLogicalNetwork -Name "LogicalNetwork02"  
Set-SCPackageMapping -PackageMapping $Mapping -TargetObject $NewResource  
  
# Import the package to the dissimilar VMM management server.  
Import-SCTemplate -VMMServer "VMMServer02.Contoso.com" -Name "New Service Template" -Release "1.0" -  
TemplatePackage $Package -PackageMapping $PackageMapping -SettingsIncludePrivate  

See Also

Create a Function that Exports a Package (Script)
Export a Package from a VMM Server and Import It to the Same VMM Server (Script)
Export a Package from a VMM Server and Import It to a Similar VMM Server (Script)