Compartilhar via


Exportar um pacote de um servidor do VMM e importá-lo para um servidor VMM diferentes usando mapeamento avançado (Script)

 

Aplica-se a: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Você pode compartilhar modelos entre servidores de gerenciamento do VMM diferentes exportando o modelo a partir de um servidor de gerenciamento do VMM, criando um mapeamento de pacote que redireciona os recursos do modelo importado para os recursos do ambiente de destino e, em seguida, importe o pacote de modelo de serviço.

System_CAPS_noteObservação

O script neste tópico supõe que você salvou a função de Crie uma função que exporta um pacote (Script) com o nome ServiceTemplate.ps1 de exportação.

Isenção de responsabilidade

O script a seguir carrega e usa a função chamada ServiceTemplate.ps1 de exportação para exportar o modelo especificado. Em seguida, ele cria um mapeamento de pacote e importa o modelo para um servidor de gerenciamento do VMM é diferente do qual o modelo foi exportado, usando o mapeamento de pacote para redirecionar os recursos.

<#
  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