Configure virtual machine for nested ESX/ESXi with PowerCLI

I’ve been working with several scripts in a lab recently. Most of these labs require additional ESXi hosts (namely vCheck testing) so I’ve been propping up some nested ESXi virtual machines. When I create a virtual machine to run nested ESXi, I typically set three advanced configuration options:

monitor_control.restrict_backdoor = TRUE
monitor_control.vt32 = TRUE
SMBIOS.reflectHost = TRUE
  • The first option listed allows you to run virtual machines inside your nested ESXi installations.
  • The VT32 option is specifically geared for Intel hardware; if you are using AMD hardware you’ll probably want to use monitor_control.enable_svm = TRUE instead.
  • The final option is not really required; it simply makes the nested ESXi host look more like a physical server. If you do this on an HP server, the virtual ESXi host appears as an HP instead of being a VMware, Inc. Virtual Machine Platform.

While three copy/paste operations into the advanced settings window isn’t challenging or time consuming, I thought it would be better if this could be done with PowerCLI.

[cc lang=”powershell”]
#Monitor Control/Restrict Backdoor
$extrarbd = New-Object VMware.Vim.optionvalue
$extrarbd.Key=”monitor_control.restrict_backdoor”
$extrarbd.Value=”TRUE”

#Monitor Control/VT32
$extravt32 = New-Object VMware.Vim.optionvalue
$extravt32.Key=”monitor_control.vt32″
$extravt32.Value=”TRUE”

#SMBIOS/Reflect Host
$extraref = New-Object VMware.Vim.optionvalue
$extraref.Key=”SMBIOS.reflectHost”
$extraref.Value=”TRUE”

#Create a Machine Config Spec using the three option values specified above
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.extraconfig += $extrarbd
$vmConfigSpec.extraconfig += $extravt32
$vmConfigSpec.extraconfig += $extraref

#Get a VM View collection of all the VMs that need to have these options
$vms = get-view -viewtype virtualmachine |where {$_.name -eq “mytestesxi01”}
foreach($vm in $vms){
$vm.ReconfigVM($vmConfigSpec)
}
[/cc]

I’ve used this on two virtual machines and it appears to work okay. Please feel free to drop a comment if you have any questions.

Posted in Scripting, Virtualization | 1 Comment

PowerCLI vCheck 5.38

It has been a little over 3 months since I’ve posted an update to vCheck. I still have some features and bug checks I’d like to add, but figured I’d share the current state. Here are the in-code comments for the new sections:

# Version 5.38- bwuch: bug fix with 'connectionstate' warning
# Version 5.37- bwuch: added SYMC to VCB check for Symantec Backup Exec 2010
# Version 5.36- bwuch: changed snapshot function
# Version 5.35- bwuch: Added section with Powered Off VMs showing the last powered on date/event.
# Version 5.34- bwuch: Added the CBT tracking code provided by rhys on vCheck comments
# Version 5.33- bwuch: Modified Cluster config check to vCheck output format http://www.peetersonline.nl/index.php/vmware/check-vmware-configuration-with-powershell/
# Version 5.32- bwuch: Hack to make report look better in Outlook.

For those of you looking for some detail, keep on reading:

5.32 – A single line of code was retro-fitted to make the email report look a little better in Outlook 2007/2010. You can read about that change here: http://enterpriseadmins.org/blog/scripting/minor-update-to-vcheck-5-31-beta-testers-required/

5.33 – I took the really cool looking cluster config check from the following site: http://www.peetersonline.nl/index.php/vmware/check-vmware-configuration-with-powershell/ and changed the output so it would appear in vCheck. This is a really cool looking report with solid data, but it doesn’t really look good on clusters with more than 3 or 4 hosts (due to the table resizing). If you want to disable/hide these checks, you need to set the variables on lines 182, 183 and 184 to $false.

5.34 – A user over at Virtu-Al.net posted some code in the comments that allows checking of Change Block Tracking (a backup mechanism based off the vStorage API for Data Protection). That code has been incorporated into this version.

5.35 – A user at Virtu-Al.net posted a request for powered off VMs with the time they were last powered on. The code was already available here http://blogs.vmware.com/vipowershell/2009/10/when-was-the-last-time-that-vm-was-powered-on.html so I incorporated it into vCheck result format.

5.36 – I changed the snapshot checks to make use of some PowerCLI advances; removing some custom functions that Alan had in the original vCheck and possibly improving performance for environments with large numbers of snapshots. The snapshot code is available independently here: http://enterpriseadmins.org/blog/scripting/vsphere-snapshot-report/

5.37 – A user posted a comment to the vCheck 5.31 thread stating that their backup product has snapshots named “SYMC*” that should appear in the VCB Garbage check. Updated code as requested.

5.38 – During some test runs prior to posting I encountered another PowerCLI warning related to changes in the functions in PowerCLI 4.1. I resolved that specific issue in this version.

You can download the updated version here: vCheck5.38.ps1

Please feel free to leave a comment with any suggestions or problems you may encounter.

Posted in Scripting, Virtualization | 13 Comments

vSphere Snapshot Report

I have been working on addressing a comment I noticed on the Virtu-Al vCheck comments (http://www.virtu-al.net/featured-scripts/vcheck/). The issue relates to a warning message returned in the “checking snapshots” section:

10:58:25 AM ..Checking Snapshots
WARNING: Unable to populate snapshot size due to unsiffucient permissions.

The existing code worked for me (I did not receive the above warning in any of my environments). The problem may be related to the version of PowerCLI [version 4.1 U1 build 332441 appears to work well]. The snapshot code inside vCheck is fairly complex, and I had some trouble following what was happening. After a few minutes of trying to following along I gave up and tried to write the same thing a different way. Here is the modified section that can be ran independently…troubleshootSnapshots.ps1

I’m looking for testers (again). If this code works for you, please let me know. If this code proves to work better I’ll update my version of vCheck to include the new method.

Posted in Scripting, Virtualization | Leave a comment

2011 Governor’s Public Service Achievement Award

In the world of scripting and automation I find it easy to get lost in technical requirements and code while forgetting the reason people automate tasks — improved accuracy and cost savings. Earlier this week my co-workers and I were reminded of these reasons. Our team was recognized with the Indiana 2011 Governor’s Public Service Achievement Award.


From left to right: Tony Lewis, Clayton Molnar, Governor Mitch Daniels, Brian Wuchner, Bob Clarke

Being recognized at this level was a great honor for our team. Now we are energized and ready to find new and exciting ways to improve accuracy and decrease costs.

Enough with patting myself on the back…it is time to code! I’m working on yet another vSphere snapshot report script which should be posted in a day or two…stay tuned.

Posted in Scripting | Leave a comment

Windows Disk Partition Alignment Best Practices

I was recently sent the following link that describes disk partition alignment best practices for SQL Server:

http://msdn.microsoft.com/en-us/library/dd758814.aspx

This is a really good article — it describes the performance implication of mis-aligned drives — which apply to all Windows installs, not just SQL servers. I’ve participated in alignment discussions several times — specifically as it relates to virtual machine disks. What I like about this article and the ‘performance impact’ section is the test description. The results are not VMware or SAN/array specific — they relate to local disk (SAS DAS). The issue of alignment is not a VMware discussion — it is primarily a Windows OS discussion.

Posted in Virtualization | Leave a comment