Import a Missing Service Template from a Previous Backup (Script)

 

Updated: May 13, 2016

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

The script in this topic restores a service template that has been deleted from the System Center 2012 – Virtual Machine Manager (VMM) library. It assumes that you have backed up the template files using the sample script in Perform a Nightly Backup of Service Templates (Script).

Disclaimer

The following script prompts the user for a template name and release, and then gets the missing template from the backed-up template packages. The script then imports the template into the library. If you changed the path when you backed up the template, update the path in the following script to match your backup path.

  
# Description:   This script restores a service template that has been inadvertently  
#                deleted from the library from a previously exported package.  
  
# Get the missing template form yesterday's backed-up service template packages.  
$Template = Read-Host "Enter the name of the missing service template"  
$Release = Read-Host "Enter the release of the missing service template"  
$ServiceTemplate = "$Template.$ Release.xml"  
$Yesterday = (Get-Date).AddDays(-1)  
$Date = Get-Date -Date $Yesterday -Uformat "%Y_%m_%d"  
$Package = Get-SCTemplatePackage -Path D:\TemplateExports\$Date\$ServiceTemplate  
  
# Import the service template into the library.  
Import-SCTemplate -TemplatePackage $Package -SettingsIncludePrivate  
  

See Also

Import-SCTemplate