1
votes

I’m have an Azure PowerShell challenge.

I am trying to create a VM with a static IP based on an existing disk.

I have run the following and can see my disk in the list of VM disks

Add-AzureDisk -DiskName $diskname -MediaLocation $medialocation -Label "bootdisk" -OS "Linux"

However when I run the following script:

Set-AzureSubscription -SubscriptionName "my subscrption"  -CurrentStorageAccountName "my storage account"


$vmImg = New-AzureVMConfig -Name $vmname -InstanceSize Large -DiskName $diskname -Verbose |
         Set-AzureSubnet -SubnetNames "my subnet" |
         Set-AzureStaticVNetIP -IPAddress "192.168.58.101" 


  New-AzureVM -ServiceName $cloudservicename  -VMs $vmImg 

I get this error

New-AzureVM : CurrentStorageAccountName is not accessible. Ensure the current storage account is accessible and in the same location or affinity group as your cloud service

I did some research and found that is an issue when the cloud service already exits. However, I have tried all the workarounds suggested including allowing the New-AzureVM to create the cloud service and to create it manually.

Have you come across this? The reason I need the static IP is that everything in the VM breaks if I allow dynamic IP.

Any suggestions would be greatly appreciated.

1

1 Answers

2
votes

Try the following and see if it resolves your issue.

Clean up :-

Clean out %appdata%\Windows Azure Powershell. Close out all powershell instances add-azureaccount

Step 1:

Set-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN" -CurrentStorageAccount $storageAccountName

Step 2: Check if the IPAddress is available.

Test-AzureStaticVNetIP –VNetName $vnetName –IPAddress 10.0.0.9

Step 3:

New-AzureVMConfig -Name "testvmkv21" -InstanceSize Basic_A2 -Label "testvmkv1" -ImageName (Get-AzureVMImage)[88].ImageName | Set-AzureSubnet "subnet-1" | Set-AzureStaticVNetIP -IPAddress 10.0.0.9 | add-azureprovisioningconfig -adminusername "myuser" -windows -password "!!abc039"| Add-AzureEndpoint -LocalPort 80 -Name 'HTTP' -Protocol tcp -PublicPort 80 | Add-AzureEndpoint -LocalPort 443 -Name 'HTTPS' -Protocol tcp -PublicPort 443| New-AzureVM -ServiceName "testvmkv21" -Location "East US" -VNetName "eastusvnet"