Export (0) Print
Expand All

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

Updated: November 1, 2013

Applies To: System Center 2012 - Virtual Machine Manager, System Center 2012 R2 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.

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.


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 

Param (
   [String] $ServiceTemplate=$(throw "Please provide the name of a service template."),

   [String] $Release=$(throw "Please provide a release for the service template."),

   [String] $Path=$(throw "Please provide a share path."),

   [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

For additional resources, see Information and Support for System Center 2012.

Tip: Use this query to find online documentation in the TechNet Library for System Center 2012. For instructions and examples, see Search the System Center 2012 Documentation Library.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft