Virtually Sober

If there is free booze and Virtualization; I'm there!

Automated vSphere VM sizing & cost calculator for DR to Microsoft Azure

When planning DR or migrations from VMware vSphere to Microsoft Azure, one very important task is to configure the appropriate VM/instance sizing to match your current VM settings. This needs to be done in advance for the following key reasons:

  • Ensure adequate performance of the VM when running in Azure
  • Select the VM size that supports the number of vNICS and vDisks required
  • Perform a cost analysis of VM runtime and storage costs

In ZVR 5.0 selecting the Azure VM size is very easy in the GUI:

automated-vsphere-vm-sizing-ss1

But what this doesn’t do is tell you exactly which one to pick and neither does it tell you how much it is going to cost!

So how are you going to select the correct instance size and calculate the cost for all your VMware VMs? That sounds like a manual and tedious task that thousands of people are going to have to tackle over the next few years. Of course, you already know I have something that is going to help you otherwise you wouldn’t be reading this far!

Click on the link below to download a small PowerShell script and CSV which will automatically calculate all of this for you. All you need to do is specify the vCenter IP, your username, password (with view permissions) and that’s it! You’ll need to ensure you have PowerCLI installed before running it:

AzureVMSizingToolv1.zip

Automated vSphere VM sizing SS2.PNG

The script uses the supplied CSV as a template to select the correct Azure VM sizes, connects to your vCenter, pulls a list of the VMs, counts vNICs and vDisks then recommends the minimum size for each VM and calculates the cost. The template and script supplied are using current US East pricing and I included only the VM sizes that were applicable for my VM performance profile. You can easily add your own preferred VM sizes and update prices etc:

Automated vSphere VM sizing SS3.PNG

After running the script, you will see 2 exported CSV files in the same directory. These are:

  • AzureVMSizingExport.csv
    – A list of all the vSphere VMs, their size, settings and the appropriate Azure VM size to use
  • AzureVMSizingExportSummary.csv
    – A summary of the total cost of replicating to Azure, using ZVR to replicate & the cost of DR testing

automated-vsphere-vm-sizing-ss4

automated-vsphere-vm-sizing-ss5

And that’s it! I hope you find this useful, it saves you a bunch of time and helps you in your journey to the cloud. If it did any of these then please like, tweet and share this post! Happy scripting,

Joshua

13 responses to “Automated vSphere VM sizing & cost calculator for DR to Microsoft Azure

  1. Jamie February 16, 2017 at 6:21 pm

    Hey, when I’m running this I’m only pulling the data about the cost. I’m getting some errors about powershell/vm snap-ins, do you have any idea how to fix the errors?

  2. Rob Sims February 16, 2017 at 8:44 pm

    Could see this being a very useful script! When running it on our lab, every VM is getting registered as Linux as its guest OS. Thoughts on what I might be doing wrong?

    • Joshua Stenhouse February 16, 2017 at 8:55 pm

      Hey Rob. On script line 107 can you add the following snippet:

      write-host “GuestID =” $VM.GuestID
      write-host “Script Interpreted This As: $VMGuestOS”

      Run the script again, but in PowerShell ISE, then can you tell me what the GuestIDs of the VMs being identified as Linux? Thanks!

      • robsims2013 February 16, 2017 at 9:05 pm

        Looks like the guest IDs are showing up blank. I looked over the VMs to see if it might be VMWare Tools related but while a couple are uninstalled or in a guest managed state, most are running on the current version just fine. I also tried it partially on one of our production sites to see if it had something to do with the lab setup but was getting the same – Not pulling any guest IDs.

        Thanks!
        Rob

      • Joshua Stenhouse February 16, 2017 at 9:15 pm

        Interesting. There is definitely something going wrong with the Get-VM command on line 86, which shouldn’t be happening as it’s a very simple command:

        $VMList = get-vm | Where {($_.PowerState -eq “PoweredOn”) -and ($_.Name -notlike “*Z-VRA-*”) -and ($_.Name -notlike “*ZVM*”) -and ($_.Name -notlike “*NestedESXi*”) -and ($_.Name -notlike “*vCenter*”)}

        Add the below at line 93 to see a complete list:

        $VMList | select Name,GuestID

        What version of vSphere and PowerCLI are you using? Does the account you are using to connect to the vCenter have any permission restrictions on any VM folder etc? I’m using vCenter 6.5 with PowerCLI 6.3.0.8258 if that helps. Thanks for troubleshooting, always half the fun!

      • Rob Sims February 16, 2017 at 9:29 pm

        Think I figured it out, thanks for mentioning the Get-VM command as that got me looking at it. On my workstation that I was running it from I’m using PowerCli 5.1R1 and was connecting to vCenters on 6.0 Looks like the variable name is just “Guest” instead of “GuestID” in this version. Changing it to that makes the script correctly look for Windows instance pricing.

        Agreed on the troubleshooting, I especially like it when someone else has already written the code. 😉

    • Joshua Stenhouse February 16, 2017 at 9:44 pm

      Glad to hear it is working and thank you for the feedback. To compensate for this I’ve updated the script to use this instead:

      # Getting Guest OS for pricing
      if (($VM.GuestID -like “*windows*”) -or ($VM.Guest -like “*windows*”))
      {
      $VMGuestOS = “Windows”
      }
      else
      {
      $VMGuestOS = “Linux”
      }

  3. Rob Sims February 16, 2017 at 9:52 pm

    Thanks Joshua! I should probably use this as a reminder to update my PowerCLI anyway, but I’ll remember what we found here anyway.

    If I could suggest one other change (though of course I can simply change it myself on our side) – Line 86 lists the VM name types to ignore. in ($_.Name -notlike “*Z-VRA-*”), if you removed the last dash in the name before the wildcard, it would also ignore VRAHs which we’d also probably not care about in terms of replication pricing.

    Thanks again, excited to see what kind of uses we get out of this going forward.

  4. Kopper February 17, 2017 at 3:22 am

    really good script
    it will make life easier for sure

  5. karlochacon February 17, 2017 at 3:25 am

    Joshua, is the zip attached the script with the latest version? I mean with changes that commented in the comments?

Leave a Reply

%d bloggers like this: