New-AzureResourceGroup

New-AzureResourceGroup

Creates an Azure resource group and its resources.

Syntax

Parameter Set: Default
New-AzureResourceGroup -Location <String> -Name <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via Gallery and template parameters file
New-AzureResourceGroup -GalleryTemplateIdentity <String> -Location <String> -Name <String> -TemplateParameterFile <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via Gallery and template parameters object
New-AzureResourceGroup -GalleryTemplateIdentity <String> -Location <String> -Name <String> -TemplateParameterObject <Hashtable> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via Gallery without parameters
New-AzureResourceGroup -GalleryTemplateIdentity <String> -Location <String> -Name <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template file and template parameters file
New-AzureResourceGroup -Location <String> -Name <String> -TemplateFile <String> -TemplateParameterFile <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-StorageAccountName <String> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template file and template parameters object
New-AzureResourceGroup -Location <String> -Name <String> -TemplateFile <String> -TemplateParameterObject <Hashtable> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-StorageAccountName <String> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template file without parameters
New-AzureResourceGroup -Location <String> -Name <String> -TemplateFile <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-StorageAccountName <String> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template uri and template parameters file
New-AzureResourceGroup -Location <String> -Name <String> -TemplateParameterFile <String> -TemplateUri <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template uri and template parameters object
New-AzureResourceGroup -Location <String> -Name <String> -TemplateParameterObject <Hashtable> -TemplateUri <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Parameter Set: Deployment via template uri without parameters
New-AzureResourceGroup -Location <String> -Name <String> -TemplateUri <String> [-DeploymentName <String> ] [-Force] [-Profile <AzureProfile> ] [-Tag <Hashtable[]> ] [-TemplateVersion <String> ] [ <CommonParameters>]

Detailed Description

The New-AzureResourceGroup cmdlet creates an Azure resource group and its resources. This cmdlet returns an object that represents the new resource group.

An Azure resource is a user-managed Azure entity, such as a database server, database, or website. An Azure resource group is a collection of Azure resources that you deploy as a unit.

To add a deployment to an existing resource group, use the New-AzureResourceGroupDeployment cmdlet. To add a resource to an existing resource group, use the New-AzureResource cmdlet.

You can create a resource group that has only a name and location, and then add resources to it. For a complex cloud-based service, such as a web portal, you can use a resource group template. A template is a model of a resource group in JavaScript Object Notation (JSON). You can find many templates in the Azure template gallery by using the Get-AzureResourceGroupGalleryTemplate. You can also create your own templates.

To use a gallery template to create a resource group, specify the GalleryTemplateIdentity parameter. You also have the option of saving a gallery template in JSON format by using the Save-AzureResourceGroupGalleryTemplate cmdlet to save the gallery template as a .json file. Specify either the TemplateFile or TemplateUri parameter to specify that file.

You can also create a custom resource group template, either by typing in a text file or by editing a gallery template. To use a custom template to create a resource group, specify TemplateFile or TemplateUri.

The templates include parameters, which are placeholders for configurable property values, likes names and sizes. To specify values for the template parameters, use one of the following methods:

-- Specify a JSON-formatted parameter file as the value for the TemplateParameterFile or TemplateUri parameter.
-- Specify a hash table of parameter names and values as a value for the TemplateParameterObject parameter.
-- Add template parameters dynamically.

To use dynamic parameters, include them in the command. You can type a minus sign (-) to indicate a parameter name, and then press the Tab key to cycle through the available parameters. If you omit a required template parameter, this cmdlet prompts you for the value. Template parameter values that you specify at the command line take precedence over template parameter values in a template parameter object or file.

Parameters

-DeploymentName<String>

Specifies the name of a deployment for the new resource group.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Force

Forces the command to run without asking for user confirmation.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-GalleryTemplateIdentity<String>

Specifies the gallery template on which this cmdlet bases the new resource group.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Location<String>

Specifies the location in which this cmdlet creates a resource group.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Name<String>

Specifies the name of the new resource group.

Aliases

ResourceGroupName

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Profile<AzureProfile>

Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-StorageAccountName<String>

Specifies the name of the storage account for which this cmdlet creates a resource group. The default is the current storage account. If you have not selected a current storage account for your subscription, you must specify a storage account.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Tag<Hashtable[]>

Specifies an array of hash tables of tags for the new resource group. For more information about tags, see the Tag parameter of the Set-AzureResourceGroup cmdlet.

Aliases

Tags

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TemplateFile<String>

Specifies the full path of a template file that this cmdlet uses to create a resource group. You can specify a custom template file or use the Save-AzureResourceGalleryTemplate cmdlet to save a gallery template to use with this parameter.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TemplateParameterFile<String>

Specifies the full path of a file that contains template parameter values that this cmdlet specifies for the resource group.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TemplateParameterObject<Hashtable>

Specifies a hash table that contains template parameter values that this cmdlet specifies for the resource group.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TemplateUri<String>

Specifies the URI of a file that contains template parameter values that this cmdlet specifies for the resource group.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-TemplateVersion<String>

Specifies the version of the template that this cmdlet uses to create a resource group.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 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 the cmdlet by property name, but not by value.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Azure.Commands.ResourceManagement.Models.PSResourceGroup

    This cmdlet returns the resource group that it creates.

Examples

Example 1: Create an empty resource group

This command creates a resource group that has no resources. You can use the New-AzureResource and New-AzureResourceGroupDeployment cmdlets to add resources and deployments to the new resource group.

New-AzureResourceGroup -Name "ResourceGroup1" -Location "South Central US"

Example 2: Create a resource group from a custom template

This command creates a resource group named ContosoHosting based on a custom template. The TemplateFile parameter specifies the full path of the template. The TemplateParameterFile parameter specifies the parameter file, which contains the names and values of the parameters in the template. Because the command does not specify a storage account, the cmdlet uses the current storage account in the subscription.

New-AzureResourceGroup -Name "ContosoHosting" -Location "West US" -TemplateFile "D:\Templates\ContosoHosting.json" -TemplateVersion "2014-04-01-preview" -DeploymentName "ContosoHosting" -TemplateParameterFile "D:\Templates\ContosoHostingParms.json"

This command creates a resource group from a gallery template. The command specifies template parameter values.

The GalleryTemplateIdentity parameter specifies the gallery template. You do not have to save the gallery template to disk. To add template parameters, after you enter the cmdlet parameters and values, type a minus sign, and then press the Tab key. Windows PowerShell supplies a parameter, such as siteMode. These parameters do not follow the Windows PowerShell standard of initial uppercase letter. Enter a value, and repeat this procedure, as needed. If you omit a required template parameter, the cmdlet prompts you for the value.

New-AzureResourceGroup -Name ContosoRG01 -Location "West US" -GalleryTemplateIdentity "Microsoft.WebSite.0.1.0-preview1" -siteName "ContosoWeb" -hostingPlanName "ContosoHosting" -siteMode "Limited" -computeMode "Shared" -siteLocation "South Central US" -subscriptionID "9b14a38b-4b93-4554-8bb0-3cefb47abcde" -resourceGroup "ContosoRG01"

This example creates a resource group based on a gallery template that you create by using the Save-AzureResourceGroupGalleryTemplate cmdlet. The example supplies template parameter names and values in a hash table.

This command gets a gallery template by using the Get-AzureResourceGroupGalleryTemplate cmdlet. The command passes this gallery item to the Save-AzureResourceGroupGalleryTemplate cmdlet by using the pipeline operator. The command saves the template as a .json file specified folder.

Get-AzureResourceGroupGalleryTemplate -Identity "Microsoft.WebSite.0.1.0-preview1" | Save-AzureResourceGroupTemplate -Path "D:\Azure\Templates"

The second command gets the contents the template file by using the Get-Content cmdlet. The command specifies the Raw parameter, and. Therefore, the command ignores line breaks and returns a single JSON string. The command passes the template to the ConvertFrom-Json cmdlet. That cmdlet returns a PSCustomObject that represents the template. The command stores that object in the $Template variable. You can use this object to discover which parameters the template requires.

$Template = Get-Content -Raw -Path "D:\Documents\Azure\Templates\Microsoft.WebSite.0.1.0-preview1.json" | ConvertFrom-Json

The third command displays the Parameters property of the template custom object. The object also has a Resources property that represents the resources in the template.

$Template.Parameters

The fourth command creates a hash table that contains the template parameters and values. The command stores the hash table in the $Params variable.

$Params = @{siteName="ContosoWeb"; hostingPlanName = "ContosoHosting"; siteMode = "Limited"; computeMode = "Shared"; siteLocation = "South Central US"; subscriptionId = "9b14a38b-4b93-4554-8bb0-3cefb47abcde"; resourceGroup = "ContosoRG01"}

The final command creates a resource group. The TemplateFile parameter specifies the gallery template. The TemplateParameterObject parameter specifies $Params, which contains the hash table of template parameter names and values. The StorageAccountName parameter specifies the storage account in which you stored the template. If you specify the TemplateFile parameter, if you have not selected current storage account for your subscription, you must specify a storage account. The command returns an object that represents the new resource group.

New-AzureResourceGroup -Name "ContosoRG01" -Location "West US" -StorageAccountName "contosostorage01" -DeploymentName "WebDeploy01" -TemplateFile "D:\Azure\Templates\Microsoft.WebSite.0.1.0-preview1.json" -TemplateParameterObject @Params -StorageAccountName ContosoStorage

Example 5: Create a resource group that has tags

This command creates an empty resource group. This command is the same the first example, except that it assigns tags to the resource group. The first tag is named Empty. You could use it to identify resource groups that have no resources. The second tag is named Department. This tag has a value of Marketing. You can use this tag to categorize resource groups for administration or budgeting.

New-AzureResourceGroup -Name "ResourceGroup11" -Location "South Central US" -Tag @{Name="Empty"}, @{Name="Department";Value="Marketing"} 

Get-AzureResourceGroup

Remove-AzureResourceGroup

Set-AzureResourceGroup

Get-AzureResourceGroupGalleryTemplate

New-AzureResource

New-AzureResourceGroupDeployment

Save-AzureResourceGroupGalleryTemplate