Search code examples
powershellazureazure-gov

powershell script to create vm in azure government subscription


My current script to create vm in ARM or classic mode does not work; I get an error: New-AzureVM : ResourceNotFound: The hosted service does not exist.

can someone please share the powershell script to create new VM in AzureGovernment subscription? my script:

Set-AzureEnvironment "AzureGovernment"

New-AzureVMConfig -Name "test1" -InstanceSize "Standard_D14" `
                  -ImageName "myimage" | 
                   Add-AzureProvisioningConfig –Linux `
                  –LinuxUser "myuser" -Password "mypwd" | 
                   New-AzureVM –ServiceName "myservice"

I am able to create a new VM using Azure portal, but fail with powershell


Solution

  • You can use the following to connect to Azure Government with PowerShell:

    https://learn.microsoft.com/en-us/azure/azure-government/documentation-government-get-started-connect-with-ps

    From there, the VM creation. One other caveat is that the region names are different. Make sure that you are using one of the region/locations in the document.