Check VMware Configuration with Powershell

I have promised you I would post this script, so here it is!

This Powershell script generates an overview of any items that are not available to every ESX server in a VMware cluster. These items might prevent your vm’s being vmotioned by DRS or restarted by HA. Pretty serious business, I’d say!

The items involved are:
1. datastores
2. LUNs (important when using Raw Device Mappings)
3. port groups

The output is a nicely formatted HTML page showing not only which items are misconfigured, but also where the are available and where they are absent.

Here’s an example:
Compare Screenshot

And here’s the script:
Compare-Clusters (Rename to .ps1)

Enjoy!
Hugo

I’m not pretending that squeezing myself Baratas Ray Ban into jeans two sizes too small is fun. According to 50,000 games played (simulated) by the Predictalator, the Bengals win over the Cowboys 64.2 percent of the time and by ray bans sale an average score of http://www.cheapjerseysselling.com 28 22. The three main http://www.cheapjerseysselling.com ways cheap football jerseys to watch free TV shows online include: 1. Rivalries can be taken so seriously that it can even break up relationships. If you are curious about other stations, such as local access programing, scroll through to program listing to highlight a specific station, then press the “Info” button on your remote. So, he’s got all the freedom in the world. Mardy Fish managed to make it to the quarterfinals of the Farmers Classic after defeating Gilles Muller in straight sets on Thursday night at the Los Angeles Tennis Center, and is now hoping to take down Igor Kunitsyn in order to advance to the semis. The birds find it difficult to fly over the cold waters of Lake Ontario and prefer to fly around it. That always amused your kids, big tough Dad, hates needles. In 2012, Lazarus was sentenced to 27 years to life in prison for first degree murder and an additional two years for personal use of a firearm. When I was in nursing assistant training, my supervisor was constantly yelling at me to stand up straight, and I wanted to scream, “LOOK, LADY, I WILL STAND AS STRAIGHT AS YOU WANT IF YOU HAND ME SOME OF THAT PERCOCET OVER THERE,” but you don’t wanna launch into your whole medical history, and also yelling about lifting pain meds in a hospital is probably a bad idea. According to the F Internationale de Football Association, international soccer’s governing body, there is evidence that people in China might have played a game similar to soccer more than 2,000 years ago. Her lover, the Roman general Mark Antony, fared little better.. The camera takes fairly amazing pictures in good light, and even takes decent cheap jerseys pictures in poor lighting. Former Crow Scott Stevens was forced to retire last season with the after effects of concussion and ex Fremantle player Daniel Gilmore has also sought compensation. Tal como el Levi Stadium, el Soldier Field tambin recibi el 1 de diciembre de 2011 la certificacin LEED, por las caractersticas sustentables de la edificacin.Eventos:Algunos de los eventos ms importantes que ha recibido este estadio son: Una carrera de NASCAR la nica en la historia del Soldier Field en 1956. I often find GREAT decorations at the dollar storeso I suggest Wholesale China Jerseys starting there before buying on line.. We’re also pleased to see overall Personal Cloud adoption continuing to play out, as it did through the course of the year better than we had anticipated across our customer base.

My Scripting Contest Contribution

It’s done!

Today I have finished my script for the VI Toolkit Scripting Contest. This contest celebrates the release of the VI Toolkit for Windows; a collection of cmdlets for Windows Powershell that allow you to manage your VMware Infrastructure.

Alle the entries for the contest are available for public use. In fact, one of the requirements for the scripts is that they can be used by (and are useful for) anyone. Although you are very welcome to join the VI Toolkit Community and share your knowlegde, I understand some of you would rather just download the code and get it running, without the hassle of registering. So, I have decided to publish my contest entry here on my website for all of you to use and/or study. You can even use (parts of) it for your own contribution to the contest. I don’t mind. It helps us all in the long run.

Here’s the explanation of the script, as I posted it in the contest community:

Many VMware environments will consist of multiple ESX servers, with multiple HBAs, connecting to multiple SCSI Targets, having access to multiple LUNs, which are used as extents for numerous datastores. In order to be able to use Vmotion, all LUNs should be accessible on all ESX hosts in a cluster. And in order to ensure reliability and availability, each component in the chain will have to be redundant. This amounts to multiple paths to each LUN, from each ESX host. While your environment grows, the number of paths grows exponentially. My script allows you to analyse complex environments and check for missing links, misconfigurations such as a LUN not masked to one of your ESX hosts or a multipath policy that is set to a wrong value.

My Get-StorageInfo script processes all LUNs connected to ESX Servers within a specified VMware Cluster. It builds a custom collection of objects representing these LUNs, with the following properties: VMHost, LUNPath, Policy, Prefer, Datastore, Vendor, Model, VMHBA, SCSITarget, LUNID, LUNKey. The script should be dot-sourced to allow the user to view, filter and sort this collection. The script will check if it is being dot-sourced. The script also prvides the user with two functions for common sorting and filtering tasks, as well as two examples for using them.

Type Show-DatastorePaths for an overview of LUNs and path counts.

Type Show-LUNs for a detailed overview of Luns, which can be filtered by using the following parameters: VMHost, LUNID, Policy, Datastore, Vendor, Model.

Examples:

Show-LUNs -Datastore PRD -Policy mru #Finds LUNs where the datastore name contains PRD and the policy is set to MRU

$LUNCollection | Where{$_.Datastore -eq $null} | Group-Object LUNID #Shows LUN IDs that have no datastore name (e.g. RDMs or unused LUNs)

A bit more info on the inner workings of the script:

In order to get all LUNs via all different paths I go through a set of nested loops. First looping through all VMHosts in the cluster, then looping through VMHBAs, then SCSI Targets and finally LUNs.

Not all properties I wanted to use are available within these loops. Therefore, for each VMHost a collection is built containing the relationship between Datastore names and Extents (in the form of a LUN path e.g. vmhba1:0:123). This allows the script to link the datastore name to those LUN paths that are actively used. The multipath policy and preferred path and the Vendor and Model of the LUN storage device are also found by using the LUN path.

After looping through all of the above, only a fraction of the LUN references have all the properties filled in: the actively used ones. Next, the script loops through the entire collection of LUN references in the collection, matching references to the same LUN by comparing the LUNKey or UUID and copying the properties that were empty.

That’s a lot of looping, I hear you think. That’s right. And it will take some time to complete. In our environment it takes about ten minutes generating the entire collection of 1440 references to different LUNs. But the result is a very rich array of items which – using the awesome power of Powershell – can generate a lot of usefull information for your environment.

Enjoy!

UPDATE!

  • Easy to use input prompt and menu eliminate the need to edit the script before use.
  • Improved progress indicators now show percentage completed for each step.
  • Advanced logic determines the discrepancies in storage configuration between hosts. These potential configuration errors are displayed on screen with all relevant properties of the involved LUNs / Datastores!
  • Added support for Folders. Added menu choices that allow you to run the script against all VMHosts in a Folder or in a Cluster or even ALL VMHosts in your VC Server.

Get-StorageInfo (Rename to .ps1) Version 2

Test the script by adding a LUN to only one ESX server in a cluster. This misconfiguration (which will cause VMotion of a VM with files on that LUN to fail!) should be spotted by the script.

Questions? Comments? Leave a comment.

»crosslinked«

VI Toolkit Advanced Script: Set-MultipathPolicy

Quick Tip: Check out my script for setting the multipath policy on a lun.

I am planning to write an elaborate post on unleashing the complete power of the Virtual Center API using PowerShell soon! Stay Tuned!

function Set-MultipathPolicy

{

param([string]$VMHost,[string]$lunId,[string]$PolicyName)

 

# Created by Hugo Peeters, JUNE 2008

# Description: Sets the multipath policy for a specified LUN

# EXAMPLE: Set-MultipathPolicy -VMHost “ESX1.example.com” -lunId “vmhba1:0:102” -PolicyName “mru”

# Possible values for PolicyName: fixed, mru, rr

 

# Create filter for selecting the ESX host

$nvc = New-Object System.Collections.Specialized.NameValueCollection

$nvc.Add(“Name”,$VMHost)

 

# Link to host system

$HostSystem = Get-EntityView -ViewType HostSystem -Filter $nvc

 

# Link to host storage system

$HostStorageSystem = Get-View -MoRef $HostSystem.ConfigManager.StorageSystem

 

# create object for input to method

$policy = New-Object Vmware.Vim.HostMultipathInfoLogicalUnitPolicy

 

# set object properties

$policy.policy = $PolicyName

 

# Execute method

$HostStorageSystem.SetMultiPathLunPolicy($lunId,$policy)

}