Auto Deploy Deep Dive, Part 4: Troubleshooting

Part 4 of the Auto Deploy Deep Dive Series details some of the issues I encountered along the way and how to troubleshoot them.

Troubleshooting

PXE

In a VLAN’ed environment (most production, and some home labs), the native VLAN and the destination VLAN for your host may be separate. You can of course boot the host on a port with no VLANs, the move/reconfigure the port to have the correct VLANs, but I would suggest entering the PXE manager at boot and setting the proper VLAN to eliminate possible failure points. If not, you may run into this situation…

Continue reading

PowerShell Profile

In an earlier article, I described how to create a PowerShell Profile, specifically so that you could access PowerCLI snapins in the regular PowerShell or PowerShell ISE programs where you get tab completion and intellitype. However, it was buried in the midst of another article where it was hard to find.

The below PoSH will create a new profile if it doesn’t exist and add the VMware snapins, then it will open the profile file for editing. PowerShell and PowerShell ISE each have their own profile file, so run it in both if you need to.

Run the suggested commands below for the correct version of PowerCLI. If you have statements in your profile from a previous version of PowerCLI, clean them up by hand, or delete your profile and re-run the script to start with a blank profile. Note: This would wipe out any non-PowerCLI commands in your profile as well, such as those added by Chocolatey.

PowerCLI 6.5.1+

You don’t need a special profile anymore, there’s a new way to install that doesn’t require modifying the profile afterward. The instructions are simple. If you’ve set up one of the profiles below, I wrote up how to undo it.

PowerCLI 6.5 GA

Download. If you encounter errors after upgrading from a previous version, check the value of $env:PSModulePath. It should contain the path C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules rather than the older C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules. If it is incorrect, try a reboot, though the installer does not suggest one is required; that fixed the problem for me.

if (! (Test-Path $profile)) {
  New-Item -Path $profile -Type file -Force
}
''                                                        | Out-File -FilePath $profile -Append
'# Import PowerCLI modules'                               | Out-File -FilePath $profile -Append
'Get-Module -Name VMware* -ListAvailable | Import-Module' | Out-File -FilePath $profile -Append
notepad $profile

PowerCLI 6.0-6.3

if (! (Test-Path $profile)) {
    New-Item -Path $profile -Type file -Force
    'Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"' | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.DeployAutomation -ea "SilentlyContinue"'   | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.ImageBuilder -ea "SilentlyContinue"'       | Out-File -FilePath $profile -Append
    'Import-Module VMware.VimAutomation.Core'                       | Out-File -FilePath $profile -Append
    'Import-Module VMware.VimAutomation.Vds'                        | Out-File -FilePath $profile -Append
    'Import-Module VMware.VimAutomation.License'                    | Out-File -FilePath $profile -Append
}
notepad $profile

PowerCLI 5.5 and Below

if (! (Test-Path $profile)) {
    New-Item -Path $profile -Type file -Force
    'Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"'    | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.VimAutomation.Vds -ea "SilentlyContinue"'     | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.VimAutomation.License -ea "SilentlyContinue"' | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.VimAutomation.Cloud -ea "SilentlyContinue"'   | Out-File -FilePath $profile -Append
    'Add-PSSnapin VMware.DeployAutomation -ea "SilentlyContinue"'      | Out-File -FilePath $profile -Append 
    'Add-PSSnapin VMware.ImageBuilder -ea "SilentlyContinue"'          | Out-File -FilePath $profile -Append
}
notepad $profile

Verify the profile contents are correct (this should preserve existing profiles, but check that new content didn’t merge at the end of the previous content). You can add any additional PoSH commands, such as aliases, to your profile, then save the file. Restart Powershell (ISE). Your startup will take a little longer now, but you end up with tab completion, intellitype AND PowerCLI. If you messed anything up, you should still have notepad open, just edit what’s needed and restart the PoSH shell till you get it right.

PowerCLI GitHub Repo – March 2014 Updates

In March, I created my PowerCLI GitHub Repo with just two cmdlets. By the end of March, I had many more cmdlets in the repo. Here are the updates:

PowerCLI-Administrator-Cmdlets

Via http://tenthirtyam.org/per-cluster-cpu-and-memory-utilization-and-capacity-metrics-with-powercli/ (@medavamshi):

  • Get-ClusterStats – A very detailed report on current Cluster resources and rough estimates of resources available after 1 or 2 cluster member failures. Useful in predicting failure scenarios as well as an eyeball view of capacity management.

Via http://hostilecoding.blogspot.com/ (@hostilecoding):

  • Edit-v10VMs – An alternative GUI to vCenter that can edit VMs with vHW 10. Useful for those without vCenter or who do not like the vSphere Web Client.

Via http://myvirtualcloud.net/?p=5924 (@StevenPoitras and @andreleibovici) are a pair of cmdlets useful for stress-testing your storage (and vCenter, if you’re not careful):

  • Clone-VM – Spin up a specified number of clones of the named VM, using VAAI by default.
  • Unclone-VM – Provide the name of the cloned VM and stop/delete all the clones.

Via http://pelicanohintsandtips.wordpress.com/2014/03/13/creating-multiple-virtual-machines-with-powercli/ is a single cmdlet for Template deployments

  • Deploy-Template – Use an existing Template and OSCustomizationSpec to deploy multiple instances of a Template into a specified Datacenter/Folder with sequential IPs.

PowerCLI-User-Cmdlets

Via http://www.shogan.co.uk/vmware/three-powercli-scripts-for-information-gathering-vms-hosts-etc/ (@shogan85) come three cmdlets that all have the option to output to CSV as well:

  • Get-VMHostBIOSInfo – Report on the Model and BIOS of all VMHosts attached to your connected vCenter.
  • Get-VMHostESXInfo – Report on the ESX(i) version and build of all VMHosts attached to your connected vCenter.
  • Get-VMHardwareInfo – Report on the vHW version of all VMs in a specified datacenter.

Via http://hostilecoding.blogspot.com/ (@hostilecoding):

Book Review: Ender’s Game and Philosophy: Genocide is Child’s Play

Around Christmas, I picked up a book called Ender’s Game And Philosophy: Genocide Is Child’s Play. I wasn’t looking for it, but it found me when browsing the aisles of Barnes and Noble. Like many technologically-minded children of my generation, Ender’s Game remains one of my favorite novels and spawned one of my favorite series. At the time, the movie had just come out; I had just re-read the novel; and when you add 30 years from the novel’s release, the opinions of one Orson Scott Card, and another dozen plus novels and shorts, you have a wonderful world, so close to our own, yet so far away. This is a great universe in which to debate philosophy.

This book is part of a series called Popular Culture and Philosophy and weighs in at 238 pages. We all debate and philosophize, though we rarely acknowledge it. It’s what a lot of you will be doing this week around the water cooler when discussing the season finale of The Walking Dead and all the decisions the characters made. In fact, the series even has a book on The Walking Dead!

Continue reading

Auto Deploy Deep Dive, Part 3: PowerCLI, Image Builder, and PXE Boot

Auto Deploy Deep Dive Series, Part Three focuses on PowerCLI and Image Builder, puts the wrap on DHCP, and brings the first auto-deployed VMhost to life!

PowerCLI and Image Builder

We are going to use some PowerCLI next. You can find plenty of PowerCLI primers elsewhere (I suggest Alan Renouf and Luc Dekens sites for the novice. I’ve also done a few articles on Power CLI…), so I’m going to assume some familiarity with it. Connect to your vCenter server with “Connect-VIServer <hostname>” and provide your credentials. The rule we are about to create relies on a host profile and a cluster name , so first we grab that information:

Continue reading

Auto Deploy Deep Dive, Part 2: Host Profiles

In part 2 of the Auto Deploy Deep Dive Series, I will show you how to build a host profile in preparation for the deployment. Launch the vSphere Web Client and we can get started.

Host Profiles

Host Profiles are a very powerful, complicated, and finicky tool that vCenter offers. These profiles are useful for compliance checking of your hosts, to ensure settings are consistent across a cluster, and in our case, Auto Deploy. We’re only going to use a small part of the host profile’s capability, which is to allow stateful installs on the new hosts, and ignore the rest – a tale for another time.

You cannot simply create a blank host profile, but you can use an existing host to create a populated profile. This can be done a number of ways, the easiest of which is to extract a host profile from an existing host. If you don’t already have an existing host in your vCenter, you’re going to need one to continue. You can extract the profile by going to the Hosts and Clusters page and selecting the highlighted option:

Continue reading

vCenter Upgrade Order

Since vSphere 5.5 was released in September, I’ve seen a lot of blog articles related to the upgrade process. Most of these articles deal with the implementation details of some specific step – upgrading the vCSA, migrating from an older version of vCSA, fixing SSO, etc. However, it seems like one of the most common questions in the freenode #vmware channel is still, “In what order do I upgrade my vCenter without breaking things?” Let’s answer that question at a high level, without getting into the implementation details.

This info is based on VMworld 2013 sessions VSVC5690 (YouTube) and VSVC4945 (requires VMworld login) taught by Justin King, Josh Gray, and Kyle Gleed, be sure to watch the presentations for additional details.

Continue reading

Auto Deploy Deep Dive, Part 1: Auto Deploy, TFTP, DHCP

Over Christmas, I expanded my home lab with another ESXi host. It seemed like the perfect time to set up Auto Deploy so my new host could be brought online with a minimum of effort. The process requires some assembly and I ran into a few minor issues along the way, so I thought I would detail those issues for others. The process is also quite lengthy, and this will be a multi-part series. Stay tuned, and check back at Auto Deploy Deep Dive Series for the rest of the articles. Credit goes to Vladan Seget’s Auto Deploy post and VMware’s own documentation for getting me started.

Auto Deploy requires multiple components – Image Builder, PowerCLI, Host Profiles, TFTP, DHCP, and vSphere Enterprise Plus licensing for your vCenter server. You have your choice of the TFTP and DHCP providers, the rest are provided by vCenter and VMware.  For TFTP, I used SolarWinds’s TFTP server (you do not have to provide a valid email address to access the download) for Windows and ISC tftp for CentOS. I had an existing CentOS server running ISC DHCP; Windows DHCP server on Server 2003+ is fine but I skipped over it because it’s familiar to most and easy to pick up by the rest.

Continue reading

PowerShell Trick via @alanrenouf

Alan Renouf gave a vBrownBag presentation on Advanced PowerCLI 5.5R2 last night. During the show, he showed an interesting bit of code:

$output = "" | Select VmName, PgName
$output.VmName = "value1"
$output.PgName = "value2"

This was intriguing to me. The “proper” way to create an object with attributes is to use New-Object and pipeline it through some Add-Member commands.

$output = New-Object PSObject |
Add-Member -PassThru NoteProperty VmName "value1" |
Add-Member -PassThru NoteProperty PgName "value2"

That creates an excessive, and somewhat unreadable, pipeline for objects with a long list of members, especially if a member’s name is long. It’s a pretty neat trick to make your code look pretty neat.

Continue reading

PowerCLI GitHub Repo

Over the past couple of weeks, I’ve done a few PowerCLI posts, including creating some modules. To reduce the change of typos or older versions of files making it into my posts, I created a GitHub repo, https://github.com/rnelson0/powercli-modules/, that you can feel free to use. There are three modules:

  • Copy-Module – Based off the Hey Scripting Guy! module, this enhanced module allows us to load modules in the Global Modulepath (when run with admin privs) and overwrite existing modules.
  • PowerCLI-Administrator-Cmdlets – Cmdlets for an administrator. Generally speaking, these require read/write access. Example: Clone-VDPortgroup
  • PowerCLI-User-Cmdlets – Cmdlets for users. Ideal for read-only users. Example: Get-VMConsoles

Please use GitHub to send me pull requests for any bug fixes or report bugs. You can of course use comments as well.

Something I forgot to mention in my post on creating modules: If you use the snippets and fill out all the comments, Get-Help Your-Cmdlet will use that information and generate full help files for you. Very helpful!