Thank you for your script, it was very helpful to create AVS quickly. But one of my VM was delete, but the script was unable to recreate it. I tried using the JSON file to recreate it, but each time I had a error code tell me on the parameter -VM, ResourceGroup is a readonly object. Do you have a workarround, or this is a mistake from my side? Regards, Emmanuel
I tried this with vers. 1.05 which failed but then noticed it said it probably would after June 2016. So is there a new complete version of the script ? One that supports managed disks , etc. ? Thanks
Hi Samir, Thanks for this script. Does it support Managed Disks? Cheers
Modified the script as per last update from Jamesatighe. It runs through without issues but doesnt actually create the VM without any error message. Validating the Vm Existence ... WARNING: Breaking change notice: In upcoming release, top level properties, DataDiskNames and NetworkInterfaceIDs, will be removed from VM object because they are also in StorageProfile and Net workProfile, respectively. Validating the As Existence ... Validation of [schwpradfs1] and [ASADFSAUEPR2] : Success Getting the VM Object : schwpradfs1 ... WARNING: Breaking change notice: In upcoming release, top level properties, DataDiskNames and NetworkInterfac eIDs, will be removed from VM object because they are also in StorageProfile and Net workProfile, respectively. WARNING: Breaking change notice: In upcoming release, top level properties, DataDiskNames and NetworkInterfac eIDs, will be removed from VM object because they are also in StorageProfile and Net workProfile, respectively. Stopping the VM : schwpradfs1 ... Exporting the VM Config to a file : RGAUEPRD1-schwp radfs1.json ... Getting the Availability Set : ASADFSAUEPR2 ... Recreating the Azure VM [schwpradfs1] : (Step 1 : Removing the VM...) ... Recreating the Azure VM [schwpradfs1] : (Step 2 : Creating the VM...) ...
Unfortunately it just deletes the VM and fails if you use managed disks
Firstly thanks for the script Samir! I have added a little bit to the script to allow for VMs with managed disks as this would not work without a little change. You need to know the Storage Account type of each disk which I have added to the script parameters as below [Parameter(Mandatory=$False, Position=3)] [string]$OSStor age, [Parameter(Mand atory=$False, Position=3)] [string]$DataSt orage Then in the Set-AsSetting function simply add the following script to accommodate for Managed Disks # New section added to allow for managed disks if ($VmObject.Stor ageProfile.OsDi sk.VHD -eq $null) { $VMObject.Stora geProfile.OsDis k.ManagedDisk.I d = (Get-AzureRMDis k | ?{$_.name -eq $VMObject.Stora geProfile.OsDis k.Name }).Id $VmObject.Stora geProfile.OsDis k.ManagedDisk.S torageAccountTy pe = $OSStorage } $VmObject.Stora geProfile.OsDis k.CreateOption = 'Attach' for ($s=1;$s -le $VmObject.Stora geProfile.DataD isks.Count ; $s++ ) { $VmObject.Stora geProfile.DataD isks[$s-1].Crea teOption = 'Attach' if ($VmObject.Stor ageProfile.Data Disks[$s-1].vhd -eq $null) { $VmObject.Stora geProfile.DataD isks[$s-1].Mana gedDisk.Id = (Get-AzureRMDis k | ?{$_.name -eq $VmObject.Stora geProfile.DataD isks[$s-1].Name }).Id $VmObject.Stora geProfile.DataD isks[$s-1].Mana gedDisk.Storage AccountType = $DataStorage } I have tested this and it works like a charm. This means the script will now work for both vhd blobs and managed disks. The usage will be the same except for the Storage Account Type being added as below ./Set-ArmVmAvai labilitySet.ps1 -VmName <VMName> -AvailabilitySe tName <AS Name> -ResourceGroup <Resource Group> -OSStorage <StandardLRS or PremiumLRS etc> -DataStorage <StandardLRS or PremiumLRS etc> Hopefully this will help a few people.
Hi James, I've tried adding code provided by you but it is throwing error in powershell console. It will be a great help if you can provide complete modified script which is working for you for managed disk.
Hi HKulshreshtha, Assuming the above is all correct, then there is a missing } at the end. { $VmObject.StorageProfile.DataD isks[$s-1].Mana gedDisk.Id = (Get-AzureRMDis k | ?{$_.name -eq $VmObject.Stora geProfile.DataD isks[$s-1].Name }).Id $VmObject.Stora geProfile.DataD isks[$s-1].Mana gedDisk.Storage AccountType = $DataStorage } should be { $VmObject.Stora geProfile.DataD isks[$s-1].Mana gedDisk.Id = (Get-AzureRMDis k | ?{$_.name -eq $VmObject.Stora geProfile.DataD isks[$s-1].Name }).Id $VmObject.Stora geProfile.DataD isks[$s-1].Mana gedDisk.Storage AccountType = $DataStorage } }
Hi, I tried this additional code, and it worked for the first VM, but failed for the second one. The reason was these parts, which would return all the disk IDs for some reason: (Get-AzureRMDisk | ?{$_.name -eq $VMObject.Stora geProfile.OsDis k.Name }).Id) and (Get-AzureRMDis k | ?{$_.name -eq $VmObject.Stora geProfile.DataD isks[$s-1].Name }).Id So instead, I replaced the above with the following: (Get-AzureRMDis k -ResourceGroupN ame $VmRG -DiskName $($VMObject.Sto rageProfile.OsD isk.Name)).Id and (Get-AzureRMDis k -ResourceGroupN ame $VmRG -DiskName $($VmObject.Sto rageProfile.Dat aDisks[$s-1].Na me)).Id Hope this helps.
Hi Samir, The script works almost flawlessly for me. It does redeploys the machine, however I have a DS machine, and when it is chooses a diagnostics storage account, it chooses the storage account from another region machine is in WE and gets the storage account from NE for diag... Which machine of course fails to start until I remove diag. It also configures diagnostics for machines which did not had it turned on before. I would appreciate your thoughts on this. I saw other also had some diag related issues. Thanks, Daniel
I lost the VM when I ran the script. How can I restore that VM from JSON? Can you please the exact command.
gwdacsap02d Private IP address 10.6.5.4 10.6.5.4 Canada Central Virtual network/subnet main-vnet/Adobe-Campaign-Dev-A pp-Subnet gwdacsapst03 I can answer it myself, may be will help others too Log on your Azure account by Add-AzureRmAcco unt and run below commands one by one: #Choose subscription Select-AzureRmS ubscription -SubscriptionId <Specify-Subscr iptionId> #Get Network Interface $nic = Get-AzureRmNetw orkInterface -ResourceGroupN ame <Specify-resour ce-group-name> -Name <Specify-nic-na me> #Create Availability Set and get it New-AzureRmAvai labilitySet -ResourceGroupN ame <Specify-resour ce-group-name> -Name <Specify name for availability set> -Location "<Specify Location for example Canada Central>" $avset = Get-AzureRmAvai labilitySet -ResourceGroupN ame <Specify-resour ce-group-name> -Name <the name specified in last command> #Set VM name, size and availability set $vmconfig = New-AzureRmVMCo nfig -VMName "<Specify-VM-na me>" -VMSize "Standard_F2s" -AvailabilitySe tId $avset.ID # Set VM OS disk $vmconfig = Set-AzureRmVMOS Disk -VM $vmconfig -Name osdisk -VhdUri <Specify VHD URL> -CreateOption attach -Linux #Set VM data disk $vmconfig = Add-AzureRmVMDa taDisk -VM $vmConfig -Name appdisk01 -VhdUri <Specify VHD URL> -Lun 0 -CreateOption attach -Caching none -DiskSizeInGB 500 #Set Network Interface $vmconfig = Add-AzureRmVMNe tworkInterface -VM $vmconfig -Id $nic.Id #Deploy VM New-AzureRmVM -ResourceGroupN ame <Specify-resour ce-group-name> -vm $vmconfig -Location "<Specify Location for example Canada Central>"
I can answer it myself, may be will help others too Log on your Azure account by Add-AzureRmAccount and run below commands one by one: #Choose subscription Select-AzureRmS ubscription -SubscriptionId <Specify-Subscr iptionId> #Get Network Interface $nic = Get-AzureRmNetw orkInterface -ResourceGroupN ame <Specify-resour ce-group-name> -Name <Specify-nic-na me> #Create Availability Set and get it New-AzureRmAvai labilitySet -ResourceGroupN ame <Specify-resour ce-group-name> -Name <Specify name for availability set> -Location "<Specify Location for example Canada Central>" $avset = Get-AzureRmAvai labilitySet -ResourceGroupN ame <Specify-resour ce-group-name> -Name <the name specified in last command> #Set VM name, size and availability set $vmconfig = New-AzureRmVMCo nfig -VMName "<Specify-VM-na me>" -VMSize "Standard_F2s" -AvailabilitySe tId $avset.ID # Set VM OS disk $vmconfig = Set-AzureRmVMOS Disk -VM $vmconfig -Name osdisk -VhdUri <Specify VHD URL> -CreateOption attach -Linux #Set VM data disk $vmconfig = Add-AzureRmVMDa taDisk -VM $vmConfig -Name appdisk01 -VhdUri <Specify VHD URL> -Lun 0 -CreateOption attach -Caching none -DiskSizeInGB 500 #Set Network Interface $vmconfig = Add-AzureRmVMNe tworkInterface -VM $vmconfig -Id $nic.Id #Deploy VM New-AzureRmVM -ResourceGroupN ame <Specify-resour ce-group-name> -vm $vmconfig -Location "<Specify Location for example Canada Central>"
Our Requirement is to Create two Virtual Machines using an existing image (specialised) and both the virtual machine should be in a single availability set. 1) Will there be any impact in the production like application crash 2) Do we need to take any pre-cautionary measures to make sure this task should get success even if the existing VM is in Production. I had already tried this PowerShell script in a lab environment, it is working absolutely fine but still we would like to know any pre-cautionary measures has to be taken before proceeding this task. please suggest.
1) What do you mean ? you need to know that the virtual machines under an AS should be configured to work as a load balanced farm or a cluster, which means that they can make the same work independently.2 VMs under a Availability Set means that if a VM crashes do an Azure issues (Hardware, network, hyper-visor, wrong fabric update), the second VM will not fail too 2) If you will use the script on a production VM, keep in mind that if the script fail after the removal step, your VM will no longer exist, but i have made an Export step to export the configuration of the VM to a local file. This way you will be able to create it again (The disks of the VM will never be removed anyway)
Could you update the script to select the same diagnostics storage and enable diagnostics as per original VM. One can do it by hand but it ends up calling the friendly names of the diagnostics something different to the original VM. PS also resource health break when doing this. PPS did you notice computer name turns to '-' in the essential pane - apparently a platform issue?
Hi Samir, I need to add a VM to a availability set (forgot to do it during the VM creation), and I found your great script. I have seen on the description that the script is likely to fail with the latest version of Azure PowerShell. :( Is there a way that you know of that I can get a previous version of the Azure PS Cmdlets from somewhere? Thanks! P.
Actually since everyone else here said they recently tried the script (as far as Sep/16) and it work, I gave it a try and all went well. As someone else said, I had to reinstall extensions and set the diagnostics again (but I took a screenshot before I made the move). The script does give a warning that the current usage of tags in the scripts is going to be deprecated soon. So the script will have to be updated then.