Forum Discussion

Antwaynio97's avatar
Antwaynio97
Copper Contributor
Jul 10, 2020

Deploying VM Using ARM Template

Hey guys. I'm trying to deploy a VM using the ARM template. These are the commands below that was run in PowerShell.

 

echo "New-AzResourceGroupDeployment -Name "dplisvvm$postfix" -ResourceGroupName "$rgName" -TemplateFile "VHDtoImage.json" -userStorageAccountName "$storageaccount" -dnsNameForPublicIP "$vmName" -subscriptionId "$mysubid" -location "$location" -vmName "$vmName" -vaultName "$kvname" -vaultResourceGroup "$rgName" -certificateUrl https://vaulto.vault.azure.net/keys/Arthur/cf9ba64e6bb24adfa943ed9d5ab72ce0.Id -vhdUrl "$vhdUrl" -vmSize "Standard\_A2" -publicIPAddressName "myPublicIP1" -virtualNetworkName "myVNET1" -nicName "myNIC1" -adminUserName "Aruzki19" -adminPassword "Antwaynio97101#"


New-AzResourceGroupDeployment -Name "dplisvvm$postfix" -ResourceGroupName "$rgName" -TemplateFile "VHDtoImage.json" -userStorageAccountName "$storageaccount" -dnsNameForPublicIP "$vmName" -subscriptionId "$mysubid" -location "$location" -vmName "$vmName" -vaultName "$kvname" -vaultResourceGroup "$rgName" -certificateUrl https://vaulto.vault.azure.net/keys/Arthur/cf9ba64e6bb24adfa943ed9d5ab72ce0.Id -vhdUrl "$vhdUrl" -vmSize "Standard\_A2" -publicIPAddressName "myPublicIP1" -virtualNetworkName "myVNET1" -nicName "myNIC1" -adminUserName "Aruzki19" -adminPassword "Antwaynio97101#"

 

And below is the error I received 

 

New-AzResourceGroupDeployment: Cannot bind parameter 'adminPassword'. Cannot convert the "Antwaynio97101#" value of type "System.String" to type "System.Security.SecureString".

 

Can anyone assist?

3 Replies

  • hkarthik_7's avatar
    hkarthik_7
    Copper Contributor

    Hello Antwaynio97, You are passing the password as a plain text. Rather convert it to a secure string and try again. Something like this - 

     

        New-AzResourceGroupDeployment `
            -Name "dplisvvm$postfix" `
            -ResourceGroupName "$rgName" `
            -TemplateFile "VHDtoImage.json" `
            -userStorageAccountName "$storageaccount" `
            -dnsNameForPublicIP "$vmName" `
            -subscriptionId "$mysubid" `
            -location "$location" `
            -vmName "$vmName" `
            -vaultName "$kvname" `
            -vaultResourceGroup "$rgName" `
            -vhdUrl "$vhdUrl" `
            -vmSize "Standard\_A2" `
            -publicIPAddressName "myPublicIP1" `
            -virtualNetworkName "myVNET1" `
            -nicName "myNIC1" `
            -adminUserName "Aruzki19" `
            -adminPassword ("Antwaynio97101#" | ConvertTo-SecureString -AsPlainText -Force)
    • Antwaynio97's avatar
      Antwaynio97
      Copper Contributor

      Hello hkarthik_7 . Thanks for the assistance. I somehow encountered another challenge in deploying the VM from the generalized image. Please see screenshot attached. 

      • hkarthik_7's avatar
        hkarthik_7
        Copper Contributor

        Hi Antwaynio97 , this is because there are no parameters like -adminUsername, -adminPassword and similar values to the cmdlet New-AzResourceGroupDeployment. You have to specify the admin username for VM in the parameters template and save your password in Azure key vault and refer the URL to the secret in password section. Please specify all the certificates related values, SKU size of the VM, admin username, password, location and encapsulate everything in a parameters file. Then, you can run the cmdlet like 

        New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\EngineeringSite.json" -TemplateParameterFile "D:\Azure\Templates\EngSiteParms.json"

         

        Please run "help New-AzResourceGroupDeployment -Full" to know the complete usage of cmdlet. You can export the template and parameter files, edit them according to your need and use the command to deploy.

Resources