Export-AzResourceGroup

In this Azure article, we will discuss the syntax and usage of the Export-AzResourceGroup Azure PowerShell cmdlet with examples.

Export-AzResourceGroup

If you wish to save your resource group as a template with a JSON file format then you can use the Export-AzResourceGroup Azure PowerShell cmdlet.

Syntax:

Below is the syntax of Export-AzResourceGroup Azure PowerShell cmdlet.

Export-AzResourceGroup
Export-AzResourceGroup
 -ResourceGroupName <String>

Let’s discuss a few examples of the implementation.

Example-1:

You can run the below Azure PowerShell cmdlet and provide the resource group name.

Export-AzResourceGroup

After executing the above command, it will prompt you to provide the name of your resource group.

Export-AzResourceGroup command

Or, you can directly execute the below Azure PowerShell cmdlet with resourceGroup as a parameter.

Export-AzResourceGroup -ResourceGroupName "MyNewResGrp"

After executing the above command, I got the below output.

PS C:\Users\Bijay> Export-AzResourceGroup -ResourceGroupName "MyNewResGrp"

Path                           
----                           
C:\Users\Bijay\MyNewResGrp.json

You can see the same output here

Export-AzResourceGroup

Now, when I navigated to the above path, I found the resource group in the JSON file format.

Export-AzResourceGroup PowerShell

Example-2:

You can also use the below Azure PowerShell cmdlet to export a resource that belongs to a specific resource group.

Export-AzResourceGroup -ResourceGroupName "MyNewResGrp" -Resource "/subscriptions/5f43547b-1d2d-4a3e-ace4-88d4b600d568/resourceGroups/TestGroup/providers/Microsoft.Compute/virtualMachines/TsinfoVM"

Once, you will execute the above command, it will save the TsinfoVM as a JSON format in your current directory.

You may also like following the below articles

Wrapping Up

In this Azure PowerShell article, we discussed the syntax and usage of the Export-AzResourceGroup Azure PowerShell cmdlet with examples. Thanks for reading this article !!!