Save-AzureResourceGroupGalleryTemplate
Save-AzureResourceGroupGalleryTemplate
Saves a gallery template to a JSON file
Syntax
Parameter Set: Default
Save-AzureResourceGroupGalleryTemplate [-Identity] <String> [[-Path] <String> ] [-Force] [ <CommonParameters>]
Detailed Description
The Save-AzureResourceGroupGalleryTemplate cmdlet saves a template from the Azure template gallery as a JSON file on disk and returns the path to the saved file. You can to use the template to create Azure resource groups and deployments
A resource is a user-managed entity, such as a website, database server, or database. A resource group is a collection of resources that are deployed as a unit. You can create resources individually and add them to resource groups. However, typically, you create a resource group by using a template.
A template is a JSON string that defines a resource group for a complex entity, such as a web hosting site or web portal. The template defines the resources that are typically needed for the entity, such as websites, databases, and storage accounts, and includes parameters for user-defined values, such as the names and properties of the resources.
To get a resource group template, use the Get-AzureResourceGroupGalleryTemplate cmdlet to get a gallery template and then use the Save-AzureResourceGroupGalleryTemplate cmdlet to save the template as a JSON file. Or, you can create your own templates, either from scratch or by editing a gallery template. To verify the syntax of a template, use the Test-AzureResourceGroupTemplate cmdlet.
To use a template to create a resource group, use the New-AzureResourceGroup or New-AzureResourceGroupDeployment cmdlets. Just identify the template and provide values for its parameters.
Parameters
-Force
Suppresses the confirmation prompt. By default, if you specify a path and file name that already exists, Save-AzureResourceGroupGalleryTemplate prompts before overwriting the file.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
-Identity<String>
Specifies the identity of the gallery item. This parameter is required. The gallery item identity is also used as the name of the template file on disk with a .JSON file name extension.
Aliases |
none |
Required? |
true |
Position? |
1 |
Default Value |
none |
Accept Pipeline Input? |
True (ByPropertyName) |
Accept Wildcard Characters? |
false |
-Path<String>
Specifies the path to the directory in which the template is saved. This parameter is optional. The default is the current directory.
Aliases |
none |
Required? |
false |
Position? |
2 |
Default Value |
none |
Accept Pipeline Input? |
True (ByPropertyName) |
Accept Wildcard Characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
None
You can pipe input to this cmdlet by property name, but not by value.
Outputs
The output type is the type of the objects that the cmdlet emits.
System.Management.Automation.PSCustomObject
Save-AzureResourceGroupGalleryTemplate returns a custom object with the Path property. The Path value is the path and file name of the gallery template on disk.
Notes
The Save-AzureResourceGroupGalleryTemplate cmdlet is included in the Azure Resource Manager module beginning in module version 0.8.0.
If a file with the specified name already exists in the Path directory, the cmdlet prompts you for confirmation before replacing it. To suppress the confirmation prompt, use the Force parameter.
Examples
Example 1: Save a template
This command saves the Microsoft.WebSite.0.1.0-preview1 template to the current directory as Microsoft.WebSite.0.1.0-preview1.json.
PS C:\> Save-AzureResourceGroupGalleryTemplate -Identity Microsoft.WebSite.0.1.0-preview1
Path:
C:\ Microsoft.WebSite.0.1.0-preview1.json
Example 2: Pipe a gallery item to Save-AzureResourceGroupGalleryTemplate
This command pipes the Microsoft.WebSite.0.1.0-preview1 gallery item from the Get-AzureResourceGroupGalleryTemplate cmdlet to the Save-AzureResourceGroupGalleryTemplate cmdlet. The command uses the Path parameter to save the JSON template in an alternate directory. Because the command uses the Passthru parameter, the cmdlet returns True to indicate that the save operation succeeded.
PS C:\> Get-AzureResourceGroupGalleryTemplate -Identity Microsoft.WebSite.0.1.0-preview1 | Save-AzureResourceGroupGalleryTemplate -Path $home\Documents\MyTemplates
Path
C:\Users\User01\Documents\MyTemplates\ Microsoft.WebSite.0.1.0-preview1.json
Example 3: Save and use a gallery template
This example shows how to use a saved gallery template to create a new resource group.
It's often useful to save a gallery template to disk before using it to create a resource group or a deployment. This gives you the opportunity to review the template and the resources that it creates and to determine that values that you will use for the parameters. But, you do not need to save a gallery template before using it to create a resource group. To use a gallery template without saving it, use the GalleryTemplateIdentity parameter of the New-AzureResourceGroup or New-AzureResourceGroupDeployment cmdlets.
The first command uses the Save-AzureResourceGalleryTemplate cmdlet to save a template to disk. The cmdlet returns the path to the JSON file.
PS C:\> Save-AzureResourceGroupGalleryTemplate -Identity TechInfoSystems.GalleryServerPro.0.1.0-preview1 -Path $home\Documents\MyTemplates
Path
C:\Users\User01\Documents\MyTemplates\TechInfoSystems.GalleryServerPro.0.1.0-preview1.json
The second command uses the New-AzureResourceGroup cmdlet to create a new resource group based on the template. To specify the saved template, the command uses the TemplateFile parameter, which takes a path to a JSON file on disk. To specify the template parameters, the command uses the TemplateParameterfile parameter, which takes a path to a JSON file of parameters and parameter values.
The command returns the newly created resource group.
PS C:\> New-AzureResourceGroup -Name ContosoRG02 -Location 'South Central US' -DeploymentName DeployWeb1 –StorageAccountName contosostorage01 -TemplateFile $home\Documents\MyTemplates\TechInfoSystems.GalleryServerPro.0.1.0-preview1.json -TemplateParameterFile $home\Documents\MyTemplates\TechInfoParameters.json