TechNet
Export (0) Print
Expand All

Create a Function that Exports a Package (Script)

 

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

You can create a function to do a task repeatedly. When you call a function, it is available until the Windows PowerShell session ends. You can save a function in a Windows PowerShell script file—that is, with the .ps1 extension—so that you can call the function from other scripts. To use the function in this topic with other examples that are provided in this guide, save it with the following name: Export-ServiceTemplate.ps1.

For more information about functions, see about_Functions.

Disclaimer


The following function prompts the user for the name of a VMM management server, the name and release of a service template, and a path to place the exported template. The script then gets and exports the template.


function Export-ServiceTemplate 
(
   $VMMServer=$(throw "Please provide the name of a VMM management server."),
   $Name=$(throw "Please provide the name of a service template."),
   $Release=$(throw "Please provide a version for the service template."),
   $Path=$(throw "Please provide a path.")
)
   {
      $Template = Get-SCServiceTemplate -Name $Name -VMMServer $VMMServer | where {$_.Release -eq "$Release"}
      Export-SCTemplate -ServiceTemplate $Template -Path $Path -Overwrite
   }

Show:
© 2016 Microsoft