How to assign Tags during the creation of an Azure VM RRS feed

  • Question

  • New-AzureRmVm -Credential $Credential -ResourceGroupName "RGGroup55" -Name NewServer -ImageName Win10-N-x64 -Location "West US 2" -Size "Standard_DS2_v2" -VirtualNetworkName "TestVN" -SubnetName "TestVNSubnet" -OpenPorts 3389

    Above is the code I'm using to create a VM in Azure. What I am not getting is how to apply tags to the VM during the creation. I noticed there is a -tag parameter, but it becomes unavailable using the code above after you start using additional parameters after -ResourceGroup. Do I have to add the tags in a separate operation after the VM is created? 

    Thanks for your help!

    • Moved by jrv Thursday, September 12, 2019 5:00 PM Best forum
    Thursday, September 12, 2019 4:53 PM

All replies

  • Hi, 

    In PowerShell while creating Azure VM, there are 3 parameter set that you can use to create VM. Out of which only one parameter set has the option -Tag which you can use. 


       [-ResourceGroupName] <String>
       [-Location] <String>
       [-VM] <PSVirtualMachine>
       [[-Zone] <String[]>]
       [-Tag <Hashtable>]
       [-LicenseType <String>]
       [-DefaultProfile <IAzureContextContainer>]

    Reference: https://docs.microsoft.com/en-us/powershell/module/az.compute/new-azvm?view=azps-2.6.0 



    Thursday, September 12, 2019 5:19 PM
  • Thank you for this, however that 2nd parameter set that has the -tag parameter does not have several of the parameters that are in the 1st parameter set that I need to create the VM such as ImageName, Location, Size, etc. I am unable to create a VM using the 2nd parameter set without those available. Is there another way?

    Thanks for your help!

    Thursday, September 12, 2019 5:56 PM
  • Hi, 

    You can provide your feedback on GitHub Azure PowerShell docs. As a workaround you can use Azure CLI. 

    Reference: https://docs.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az-vm-create

    If the above response helped, please mark it as answered to help other community members. 



    Thursday, September 12, 2019 6:02 PM
  • Any update on this issue?

    If the above helped please remember to "Up-vote" and "Mark as Answer" so others in the community can benefit

    Friday, September 20, 2019 11:42 PM
  • Hello,

    Any update on this issue?

    If the suggested answer helped you solve your issue, please remember to "Mark as Answer" and "Up-Vote"so others in the community can benefit from it.

    Tuesday, September 24, 2019 5:58 AM