I created an Azure Virtual Machine successfully through the https://portal.azure.com/ user interface. I started working on an Azure Powershell script to automate the creation of similar VMs and ended up with the function below:
function Create-CentOSVirtualMachine
{
Set-AzureSubscription -SubscriptionName Pay-As-You-Go -CurrentStorageAccount "thefoobar"
Write-Output "Searching for the latest CentOS image..."
$image = (Get-AzureVMImage | Where-Object { $_.Label -like "*CentOS*" } | select -last 1)
$imageName = $image.ImageName
$imageLabel = $image.Label
$dataDiskSizeInGB = 30
$diskLabel = "thefoobar-data"
$mediaOsLocation = "https://thefoobar.blob.core.windows.net/vhds/thefoobar-os.vhd"
$mediaDataLocation = "https://thefoobar.blob.core.windows.net/vhds/thefoobar-data.vhd"
Write-Output "Creating CentOS virtual machine from:" $imageLabel
$user = "thefoobardev"
$password = "thefoobarpassword"
$vmConfig = New-AzureVMConfig -Name "thefoobar" -MediaLocation $mediaOsLocation -InstanceSize Basic_A1 -ImageName $imageName
$vm = $vmConfig | Add-AzureProvisioningConfig -Linux -LinuxUser $user -Password $password | Add-AzureDataDisk -CreateNew -DiskSizeInGB $dataDiskSizeInGB -DiskLabel $diskLabel -LUN 0 -MediaLocation $mediaDataLocation
$vm | Add-AzureEndpoint -Name 'ElasticSearchHTTP' -LocalPort 9200 -PublicPort 9200 -Protocol tcp
$vm | Add-AzureEndpoint -Name 'ElasticSearchTransport' -LocalPort 9300 -PublicPort 9300 -Protocol tcp
$vm | Set-AzureEndpoint -Name 'SSH' -LocalPort 22 -PublicPort 22 -Protocol tcp
New-AzureVM -ServiceName "thefoobar" -VNetName "MyFoobarNetwork" -VMs $vm -Location "East US"
}
To me, it appears to match what I do through the user interface (though I renamed some strings in the script to "foobar" for this public question). The script runs without any errors, and the dashboard appears to show my VM exactly as I expect it.
However, with creation of the script, I cannot connect via PuTTY:
This is normally all I would need to fill out to connect after creating the VM through the GUI. Using my script lets me connect, but shows an error after typing in the user:
This is how I enter the security details through the portal UI:
When creating from the portal, I would instead be asked for the password for the user when PuTTYing. Is there anything missing from my Powershell script that would help me connect as I am able to when creating the VM from the portal?
I tried using some of the extra Linux parameters shown in https://msdn.microsoft.com/en-us/library/azure/dn495299.aspx.
If I add -NoSSHEndpoint
or -DisableSSH
, that simply creates my VM similarly, but with one less endpoint for SSH. And if I add the endpoint back manually, I still get the same error message. If I add -NoSSHPassword
, I get the error New-AzureVM : BadRequest: The UserPassword property must be specified.