Category Archives: VMware

vCheck 6.0 released

One of the most popular scripts on my site with 26,966 downloads of v5 has been the vCheck script, for those of you who haven’t seen this yet here is a quick summary of this script:

Summary

vCheck is a vCenter checking script, the script is designed to run as a scheduled task before you get into the office to present you with key information via an email directly to your inbox in a nice easily readable format.

This script picks on the key known issues and potential issues of the virtual infrastructure and reports it all in one place so all you do in the morning is check your email.

One of they key things about this report is if there is no issue in a particular place you will not receive that section in the email, for example if there are no datastores with less than 5% free space (configurable) then the disk space section will not show in the email, this ensures that you have only the information you need in front of you when you get into the office.

This script is not to be confused with an Audit script, I don’t want to remind you that you have 5 hosts and what there names are and how many CPU’s they have each and every day as you don’t want to read that kind of information unless you need it, this script will only tell you about problem areas with your infrastructure.

Continue reading →

Using PowerShell with Internet Explorer

PowerShell is a great language, I am often amazed at how far it can actually reach and what you can gather data, write data or use data from.

Mainly I use PowerShell to manage my VMware environment but last night I broke from my comfort zone and took some time to see what I was able to do with Internet Explorer – Did you know you can programmatically browse the web with PowerShell ?  Well you can!

The Reason

First thing I needed was a reason, at the moment there is a poll for top virtualization blogs, last year I surprisingly did very well in this and would like to thank anyone who voted for me.  This year as I was filling it out and selecting some of my favorite blogs from the list.  People like Duncan Epping, Eric Sloof, William Lam, Luc Dekens, Jonathan Medd, Frank Denneman the list goes on and on and then I found my blog tucked away near the bottom amongst the other blogs beginning with V… as this is a virtualization top list you can imagine there were a few beginning with V!

Anyway, I thought there must be an easier way to allow people to vote for me than to hope they find me amongst the V’s and don’t get bored along the way and choose others so here it is:

The below script is not a cheating script, it will not make you vote for me 1000 times it will simply start internet explorer, browse to the survey and select my site for you, one this has done you are free to deselect me if you wish and also select the other 9 participants you would like to vote for.  After this just follow on through the survey and click Submit to finish.

Obviously with PowerShell I could have just added my favorite bloggers to this script and completed the survey for you but that would be cheating and I believe in the freedom to vote!

So if you have not yet voted then simply paste the following code into a PowerShell window and watch it control internet explorer and automatically select Virtu-Al from the list, the other choices are up to you!

$URL = "http://www.surveygizmo.com/s3/786135/Top-VMware-virtualization-blogs-2012"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate($URL) 
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.Document.getElementById("sg_NextButton").click()
$ie.Document.getElementById("sgE-786135-1-27-10906").Click() # Click Virtu-Al

PowerCLI Android and iPhone App

A while back I found an iPhone and iPad app which allowed you to reference the PowerCLI Cmdlets, this is quite useful when you are on the move and need a quick reference.

Today I came across a similar app for the android and also iPhone and wanted to share it.

vPowerCLI5 Reference is an app for Android which can be downloaded from here:

Android: http://droidmill.com/vpowercli5-reference-405917.html#.Txgq7ZiE6-8

iPhone: http://itunes.apple.com/us/app/vpowercli5-reference/id489731144?mt=8

This tool is to be used for referencing the VMware vSphere PowerCLI cmdlets. vSphere PowerCLI is a command-line and scripting tool built on Windows PowerShell, and is used for managing and automating vSphere.

It looks like this is a Android/iPhone friendly version of the online PowerCLI help which can be found here:

http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/index.html

image

image

 

 

 

 

 

 

 

 

 

 

This post was updated to include iPhone app.

Updating your Image Profile

If you have been using the image builder and auto deploy cmdlets which came with vSphere 5.0 then you will already know how easy it is to completely rebuild all hosts just by replacing a simple auto deploy rule with your new image profile and then rebooting your hosts.

But how do you create your new image profile ?

An Image profile normally consists of a base ESXi image downloaded from VMware and then some custom software packages added in to ensure you have all the third party addons, drivers and utilities needed for the host to work with your infrastructure.

An example of this is the EMC PowerPath Software Package or the HP ESXi Proliant offline bundle, others may include the software package needed for the vCD Agent.

Once these software packages have been added to your image profile you are then able to export it back as an offline zip file, ISO file or use it in you Auto Deploy rule-set.

But when it comes to updating you need to remember which software packages you added to which build of ESX and repeat this procedure, this can be time consuming.

Introducing Update-ESXImageProfile

Did you know that VMware has an online repository of up to date versions of ESXi Software Depots ?  You can easily add this to your Image Builder session with the following line of code:

Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml

image

Using this online depot I was able to create a script which would download any newer software packages from the base ESXi Software Depot online and compare these against your current image profile, once this has been done it will add these latest versions to your image profile ensuring you have an up-to-date Image Profile.

Of course you will need to make sure you export this as a zip again so you can use it in the future and also add it to your Auto Deploy rule-set and reboot your hosts.

See it in action

The Script

Function Update-ESXImageProfile ($ImageProfile, $tools){
	if ($ImageProfile.Readonly) {
		Write-Host "Your ImageProfile is read-only and therefore cannot be updated, please use a custom ImageProfile"
	} Else {
		Write "Loading online Software Depot"
		$SD = Add-EsxSoftwareDepot -DepotUrl https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
		If ($tools) {
			$NEWIP = Get-EsxImageProfile -Vendor "VMware, Inc." | Sort ModifiedTime -Descending | Where { $_.Name -notlike "*tools" } | Select -First 1
		} Else {
			$NEWIP = Get-EsxImageProfile -Vendor "VMware, Inc." | Sort ModifiedTime -Descending | Where { $_.Name -like "*tools" } | Select -First 1
		}
		Write-Host "New Image Profile found called $($NEWIP.Name)..."
		Write-Host "Checking for updated packages which do not exist in $ImageProfile"		
		$Compare = Compare-EsxImageProfile -ReferenceProfile $ImageProfile -ComparisonProfile $NEWIP
		$Updates = ($Compare | Select -ExpandProperty UpgradeFromRef)
		If ($Updates) {
			Foreach ($SP in $Updates) {
				$UpdatedPackage = Get-EsxSoftwarePackage | Where {$_.Guid -eq $SP}
				Write-Host "Adding $($UpdatedPackage.Name) to $ImageProfile"
				$Add = Add-EsxSoftwarePackage -ImageProfile $ImageProfile -SoftwarePackage $UpdatedPackage
			}
		}
		$OnlyInComp = ($Compare | Select -ExpandProperty OnlyInComp)
		If ($OnlyInComp) {
			Foreach ($SP in $OnlyInComp) {
				$UpdatedPackage = Get-EsxSoftwarePackage | Where {$_.Guid -eq $SP}
				Write-Host "Adding $($UpdatedPackage.Name) to $ImageProfile"
				$Add = Add-EsxSoftwarePackage -ImageProfile $ImageProfile -SoftwarePackage $UpdatedPackage
			}
		} 
		If ((-not $OnlyInComp) -and (-not $Updates)) {
			Write-Host "No Updates found for $ImageProfile"
		}
	}
}

Update-ESXImageProfile -ImageProfile "CustomImageProfile" -Tools $true

VMware vShield PowerShell Module

A while back I was asked if we could automate some areas of vShield, VMware Security suite of products.  I was asked to do this for a demo which was to be used at VMworld, having never touched vShield before I was thrown into the world of security at the deep end.  The first thing I found on my quest was the vShield API, there is a great document by VMware which explains the vShield proprietary Web-RPC API (Based on Rest API) and all the calls you would ever need to make to work with the vShield products.

Now I had the API details I knew I could easily write some PowerShell code in the form of an advanced function to work with the API, the first piece of code I wrote was a generic function which allowed me to GET, PUT, DELETE and POST to a proprietary Web-RPC based Restful API. I know PowerShell v3 will include cmdlets for this but I didn’t want to wait or add a dependency on something which wasn’t available as yet.

Continue reading →

VM Start-up script

Back in Jan 2010 I wrote a script which shut down the virtual infrastructure, this was used to ensure your VMs were shut down and then your hosts were shut down in an orderly manner, ideal for things like UPS shutdown scripts etc.

A slight spin on that is a Start-Up script, I was asked by a couple of people if I had one of these, it also becomes more relevant with the vCenter Virtual appliance, no need for HA and DRS rules or to manually search for the vCenter Virtual Appliance if there is a power outage.

The script below will connect to all hosts you define at the start, these could obviously be read from a csv, xml file or a database etc but I just define them in a variable for ease of the script.

The script will firstly connect to each of these hosts in turn, once connected it will search for the first VMs, in my case this is a couple of domain controllers, it could be database servers or any other infrastructure servers which need to come up before vCenter.   Once these VMs have been found the script will start them and wait for their tools status to be ready, this is an easy way to check that the VM is started completely.

Once the infrastructure servers are started it will then search for your vCenter VM, this could be on any of the connected hosts, it will start it and again wait until the tools return as being completely started.

Continue reading →

Migrating ESX to ESXi

image

Just released on the VMware Flings site is a fling which is designed to help when you make the move from ESX to ESXi, this tool will help you check hardware software and also that there are no lingering scripts or locally stored VMs etc.

A great tool to download and run against your environment to ensure you have caught everything before the move to the next version of ESXi. Continue reading →

vCloud Director 1.0 PowerShell Advanced Functions

Its no secret that VMware are working on vCloud Director (vCD) cmdlets, they recently surveyed the PowerShell and VMware community to make sure they had all the information needed to make this as much of a success as the vSphere PowerCLI cmdlets.

But did you know you can already use PowerShell with vCD ?  It should be no surprise to anyone who uses PowerShell to know that PowerShell does a great job with XML manipulation and API calls.

As part of vCD 1.0 there was obviously an API, this was based on REST which is essentially calls to web pages and sending/receiving data, so with the knowledge that this API is available and that PowerShell is a great way to communicate with this API all that was left was for someone to tie all this together and create some advanced functions which can be used against the vCloud API…. enter Jake Robinson.

image

Jake has been doing some great work recently, personally I have spoken to him a couple of times and had the privilege of meeting him at VMworld 2011 Las Vegas, he is a great guy and very knowledgeable about both PowerShell and vCD so the perfect guy to create some advanced functions.

The functions can be downloaded from here:

Download: https://github.com/jakerobinson/vCloud-Powershell

I would also recommend checking out his great video on what he has created and some examples of how these can be used published here on his blog (add to your RSS feed) and also embedded below. Continue reading →

PowerCLI for vCloud Director–Have your say !

VMware have recently announced a survey on the PowerCLI site, this has been setup timageo poll people for what they think would be the best way to introduce cmdlets for vCloud Director, personally I think it’s a great move and proves that VMware really does listen to their customers opinions.

Their questions not only ask how you would like the vCloud cmdlets distributed but also if you would prefer common objects like VMs and Users to be new cmdlets based towards vCloud director or to add these as additional parameters to the existing cmdlets.

Personally when answering these questions I have to remind myself of a few things and ask myself a few questions:

  • vCloud Org users or tenants are going to be interested in different things than a vSphere admin, for example, does a tenant care about the details of the datastore so long as they are getting what they paid for, do they care about things like what host the VM or even what vCenter the VM is hosted in ? With this in mind do they really want to see the full set of “vSphere Properties” for an object or would a new set of properties based on the cloud information be relevant, similar with the cmdlets, do they want to see all the vSphere cmdlets or would a more specific set of cmdlets be better ?
  • Will vCloud Admins want to connect to both the vCloud and the vCenter at the same time ?  How will this work, when connected to both what would they expect to be displayed when running Get-VM? vSphere VMs, vCloud VMs both ? How would the properties be displayed ?
  • Will vCloud admins want to take a cloud VM and perform vSphere actions against the VM ?

Continue reading →