Export (0) Print
Expand All

Create a Function that Exports a Package (Script)

Updated: November 1, 2013

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

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
Show:
© 2014 Microsoft