Search code examples
windowsgit-bashazure-cli

How do I pass an Azure resource ID to the az command line in git bash on Windows?


This question is very similar to How do I pass an absolute path to the adb command via git bash for windows?, but the answer to the latter does not work in my case, because //subscriptions/... is not a valid Azure resource Id.

Given:

VMS=( \
"/subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-master" \
"/subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-worker" \
)

I would like to start the VMs using the following command line:

az vm start --ids ${VMS[@]}

However, it does not work:

~$ az vm start --ids ${VMS[@]} | nocolor
ERROR: invalid resource ID: C:/Program Files/Git/subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-master

~$

(nocolor is an alias that drops the ansi color sequences using the approach described in https://superuser.com/a/380778/9089)

The aforementioned SO post suggests to prepend another /, which works for a file path, but does not work for an Azure resource Id:

~$ VMS=( "//subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-master" "//subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-worker" )

~$ az vm start --ids ${VMS[@]} | nocolor
ERROR: invalid resource ID: //subscriptions/d...8/resourceGroups/xyz/providers/Microsoft.Compute/virtualMachines/cks-master

~$

So, what do we do, besides using Powershell or WSL2?


Solution

  • You can use the MSYS_NO_PATHCONV=1 flag at the beginning of the az cli command.

    In your case:
    MSYS_NO_PATHCONV=1 az vm start --ids ${VMS[@]}

    See: