New-AzResource

The New-AzResource cmdlet creates a new resource. You can use it to create a resource of any type that is supported by Azure Resource Manager.

Syntax

New-AzResource
    [-Name] 
    [-Location] 
    [-ResourceType] 
    [-ApiVersion] 
    [-ResourceGroupName] 
    [-Scope] 
    [-Force]
    [-AsJob]
    [-WhatIf]
    [-Confirm]
    []

Parameters

-Name (Required)

Specifies the name of the resource to create.

String

-Location (Required)

Specifies the location for the resource. For example, East US, West US, or Southeast Asia.

String

-ResourceType (Required)

Specifies the type of the resource to create. For example, Microsoft.Compute/virtualMachines or Microsoft.Storage/storageAccounts.

String

-ApiVersion (Optional)

Specifies the API version to use for the resource type. If not specified, the latest stable API version is used.

String

-ResourceGroupName (Optional)

Specifies the name of the resource group in which to create the resource. If not specified, the resource is created in the default resource group.

String

-Scope (Optional)

Specifies the scope at which to create the resource. This can be a subscription, resource group, or management group. For example, /subscriptions/00000000-0000-0000-0000-000000000000.

String

-Force (Optional)

Suppresses confirmation messages. By default, the cmdlet prompts for confirmation if a global resource group is specified.

SwitchParameter

-AsJob (Optional)

Runs the cmdlet as a background job. Use this parameter to run the cmdlet while the main Windows PowerShell window is still active. The cmdlet submits the command to the PowerShell job runspace and returns a job object.

SwitchParameter

-WhatIf (Optional)

Shows what would happen if the cmdlet runs. The cmdlet is not run.

SwitchParameter

-Confirm (Optional)

Prompts you for confirmation before running the cmdlet. The cmdlet is not run.

SwitchParameter

Examples

Example 1: Create a storage account

New-AzResource -Name "mystorageaccount" -Location "East US" -ResourceType "Microsoft.Storage/storageAccounts" -ApiVersion "2021-09-01" -ResourceGroupName "myResourceGroup"

This command creates a storage account named mystorageaccount in the East US region within the myResourceGroup resource group.

Example 2: Create a virtual machine

New-AzResource -Name "myVM" -Location "West US" -ResourceType "Microsoft.Compute/virtualMachines" -ApiVersion "2020-06-01" -ResourceGroupName "myVMResourceGroup"

This command creates a virtual machine named myVM in the West US region within the myVMResourceGroup resource group.

Related Links