Setting VM SDRS automation levels

I learnt recently that when you Storage vMotion a VM within a datastore cluster and you check the box to select which datastore you explicitly want the VM to be migrated to, it sets the SDRS automation level for the VM to disabled.

Finding out which VMs have an automation level of disabled can be achieved with the following line:

Since I like to have VMs set to the cluster default we need a bit of PowerCLI to change the VMs back. The following code will look at all the datastore clusters on the vCenter, and all the VMs with a disabled automation level therein.

Credit goes to LucD whose posts in the VMware Communities forum formed the base of this script. The threads are here and here.

This script is designed to be used with PowerCLI 6, as per the “Import-Module” statements at the top. For previous versions of PowerCLI the lines should be replaced with adding the appropriate snapin.

If needed, this script can easily be expanded to check for Tags or Custom Attributes assigned to the VM, and only to change the automation level given the presence or absence of a tag or the value of a custom attribute.

Viewing VM CPU Masks via PowerCLI

  • This post was updated on 9th May 2017 to fix an error condition in the script.

Support for Windows Server 2012 was announced starting with ESXi 5.0 Update 2, but there was a little known flaw in this support – in that without a CPU mask, a VM could blue screen at any time. The support article KB2060019 was released which explained everything and the issue was fixed for Update 3.

It might be useful to try and track down which 2012 VM’s (it can be adjusted for Windows 8) had their CPU masked during this time, in order to remove. The following PowerCLI reports on all Windows 2012 (and R2) VM’s and displays any CPU masking they might have. You’ll then have to manually check the results and look for a 0 in the 5th most significant bit on the edx register, but I’m sure this could be automated further.


PowerCLI: Datastore Block Sizes

Before VMFS5 the block size of the datastore determined the maximum size of a hard disk that could be added to a virtual machine. In our new glorious future it now makes no difference, but VMFS datastores that have been upgraded to version 5 will retain their old block size.

The following PowerCLI will show all the datastores connected to the vCenter and their block size.

If we wish to show all datastores that have a block size larger than 1MB then we could do the following:

Creating a Cisco UCS Profile using PowerTool

Creating a Cisco UCS Profile using PowerTool

This post is going to walk through creating a powershell function to create a Service Profile on a Cisco UCS domain. Later posts in this series will look at how to assign it to a server, configure shared storage on a NetApp filer, and configure the zoning on Fiber Channel switches – essentially all the work we’d need to do to automate the creation of a physical server.

There are a few ways to create Service Profiles on a Cisco UCS domain, but if you’re looking for consistency, best practice and the possibility to automate then you’ll need to use templates – not just a Service Profile template, but templates within the Service Profile template – for vNICs, vHBAs and for any other policies. I have assumed that templates have been set up and are being used.

We are going to be using Cisco UCS PowerTool for this, so ensure you’ve got this installed on your system. You can get it from , but you’ll need a login.

Powershell: Getting a list of VM adapter types

The following code will list the VMs which have network adapters that are not VMXNET3. This is useful for knowing what you likely have to change 😉

It will output the Name of the VM, the Type of adapter and the Network (i.e. Virtual Machine Portgroup) that it is connected to.

The code will examine all the VMs on the vCenter, but you can pass parameters to the Get-VM cmdlet to reduce the scope (i.e. Get-VM -Location “Discovered Virtual Machines”).

Getting a NetApp volume size with Powershell

I ran into a problem recently where I needed to get the size of a volume from a NetApp filer so I could create a new volume (of the same size) and initialise a snapmirror relationship to it. The problem was that sometimes the snapmirror relationship would fail to start, reporting that the destination volume was too small. The fault was in how I was calculating the size of the source volume. I’m going to look at what I did wrong, and the right way to do it.

Using the Data ONTAP Powershell module, the below code shows the result of getting the properties that start with an “S” for the volume “random_volume”.

I was using the “SizeTotal” property in the output above to calculate the size of volume. When the number above is divided by 1GB it will translate to 144 GB, but this is incorrect, as System Manager reports the volume as 180 GB. So why is this number incorrect ?

The answer is also in the above output, as the “SnapshotBlocksReserved” and “SnapshotPercentReserved” values are not 0. As expected, this means a portion of the volume has been reserved for snapshots – in the above case, 20%. The catch is that “SnapshotBlocksReserved” is not in bytes, but in kilobytes. So to get the total size of the volume in bytes we must do the following:

If we then use the powershell magic of:

We get the correct result of 180 GB.

I wouldn’t recommend using the SnapshotPercentReserved property to calculate the correct total size – it is a better practice to use the exact number of blocks reserved for snapshots.

Importing UCS VLANs

I’ve had to deal with two UCS systems recently, ensuring that the configuration matches on them both, most of which I was happy to go through by hand. But the long list of VLANs was another story. I could see that they can be exported, but I couldn’t find an import ability. So, a quick search later, I found this webpage: but is very nearly what I’m after, but we need to make a little modification.

Listing Virtual Machines and Portgroups

vSphere 5.0 – If you need a list of Virtual Machines and the portgroups they are attached to:

If you need to export this to a CSV:

Getting a vSphere VM’s Network Adapters

Getting all the network adapters for a VM is an easy task:

When you remove a network adapter, vSphere will remove it’s entry in the .vmx file. In the .vmx file, the adapter configuration options are prepended by an “ethernetX” string, where X is a number between 0 and 9. Removing the adapter, removes all the appropriate “ethernetX” entries from the file. Adding an adapter to a VM will use the first available number, so if in a 5 NIC VM “ethernet2” is not present, this is where the adapter will be placed. This has the effect of calling the NIC “Network Adapter 3”.

Why does this matter ? Because we want to get our adapters in a reliable order, regardless of the number of NICs present.

The above line will work for all VM’s with less than 10 NICs. When we have 10 NICs we need to do a little bit of regex on the sort code:

This strips out the number from the name of the adapter, converts it to an int and sorts based upon that.

This was all done with PowerCLI

Sidenote: I really need to find a decent plugin for code highlighting :-/