Tag Archives: VMware

HA Slot Size Information

Do you have HA enabled cluster ? If you do then you will need to know what a slot size is, that’s if you don’t already, if you do already then just cut straight to the cool PowerCLI example….

I’m not going to explain this completely as I could never write such an excellent explanation as Duncan over at Yellow bricks, I highly recommend reading this post as it is pure excellence.

So what is a slot size ?

If you have a HA enabled cluster and have set the admission control to ‘Prevent VMs from being powered on if they violate availability constraints’, this means when your cluster does not have enough room to start VMs if a host fails then you will violate the constraints of the cluster and vCenter will not allow you to power on your next VM, but how does it know when you do not have enough room for another VM to power on ?

Continue reading →

PowerCLI: How many VMs on your Datastores ?

How many VMs do you have on your datastores ?  Do you know ? should you care ?

Yes, you should care, you should care because over saturated datastores can cause issues with IO and also cause scsi locks if you are using fibre.  So what is the sweet spot ?

Unfortunately its one of those “It Depends” situations, isn’t everything !

It depends on the type of shared storage you are using, fibre, iSCSI, NFS and also depends on the types of VMs you are using, all I can recommend is that you try and distribute your VMs evenly and try and think about the type of VMs you are putting on the same datastore, for example, if you have multiple SQL servers on the same datastore or if you have an exchange server on the same datastore as your SQL VM’s then do something out it.

The first place I would start is by reading the great Yellow-Bricks article “Max amount of VMs per VMFS volume” where Duncan tells us how he works out his sweet spot 😉

You can see how evenly you are currently distributed with the following one-liner:

Get-Datastore | Select Name, @{N="NumVM";E={@($_ | Get-VM).Count}} | Sort Name

Example Output:

Name NumVM
ESX01_Local 0
iscsi_0 0
iscsi_1 2
iscsi_2 1
NFS_1 7

And don’t forget, with the wonders of Move-VM and SVMotion we can move some VM’s around to start evenly distributing the load on our datastores.

I would also suggest monitoring from the SAN up so you can see straight way if you have a volume or LUN issue.

PowerCLI: One-Liners Checking Host Network Information

Sometimes as a consultant when performing an initial look or a healthcheck on a new system you will want to confirm all hosts have the correct network information, if there is a mis-configured vmotion portgroup or something similar then this could impact HA or if there is an incorrect DNS server then this may also have issues further down the line with your service console.

The following quick one-liners display some vital information for each host, errors can be seen at a glance, rather than checking each host individually, for us to gain this information we use the wonderful Get-VMHostNetwork cmdlet and expand a few areas of interest:

  • Remember these can be narrowed down further by adding the Get-Cluster “MyCluster” | to the start of the line.
  • Also remember this information can also be exported to a csv by adding | Export-csv “C:\info.csv” to the end of the line.

To list all ESX Hosts and their Service console information: Continue reading →

vTip – A VMware Expert updating your VI

We have all seen the message of the day setting which allows you to alter what you would like to tell your colleagues today and other than the normal fun type messages I have never seen it put to good use.  (Yes I know this is used to tell people that a host is being managed by a VI).

So you could stick with your normal messages….

Fake Message

Or you could put it to use, how would you like a vExpert, no a vGuru, no a vGod to update your Message of the Day, giving you tips and help each day and helping you along the path to virtual enlightenment ?  Well now you can.

Jason Boche has recently announced his vCalendar which is a great daily calendar with tip for each day, there is also a blog widget and netvibes or Google widget for this too, so my script takes these wonderful daily tips and adds them to a place we all visit on a daily basis…. The Virtual Infrastructure Client.

Now you can be taught a daily message by the vMan himself.

Message of the Day

The script should work in most cases apart from those companies that have complex proxy servers. – Hope it works for you !

Don’t forget to set it up as a scheduled task to run at 00:01 every night and update your VI with the next vTip.

Function vTip {
    $proxyAddr = (get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
    $proxy = new-object System.Net.WebProxy
    $proxy.Address = $proxyAddr
    $proxy.useDefaultCredentials = $true

    $webClient = New-Object System.Net.WebClient
    $webadd = "http://www.printedowl.com/CalendarNetvibeGadget.aspx?id=boche&render=1"
    $webClient.proxy = $proxy

    trap [System.Management.Automation.MethodInvocationException]{ Continue}

    $RAWTip = $webClient.DownloadString($webadd)

    if ($RAWTip -eq $null){
        $DailyTip = $null
    }
    Else {
        $DailyTip = $RAWTip -replace "[`r`n]",'' -replace '^.*<!-- google_ad_section_start -->(.*)<!-- google_ad_section_end -->.*$','$1'
    }

    $DailyTip

}

$Message = VTip

# Dont forget to change the below line to connect to your VI
Connect-VIServer MYVISERVER

$UpdateMessage = Get-View -Id SessionManager
$UpdateMessage.UpdateServiceMessage($message)

Or if your like me and do most of your work from the PowerCLI console you could remove the last 5 lines and add it to your PowerShell profile:

image

PowerCLI: APIs made easy “Project Onyx”

For those of you who are living on Mars it is VMworld, No I am not there but I am trying to keep up with all the information coming from VMworld.

One of the coolest things I have seen is “Project Onyx”

Onyx is a cryptocrystalline form of quartz, but apart from that its also a code name for a cool new app the VMware PowerCLI team are working on.

Project Onyx basically allows you to record what you are doing in the virtual infrastructure client and turn it into PowerCLI scripts, so all those things you wanted to script but never knew how can now be achieved.

The PowerCLI team will be giving this new tool to a select few at VMworld to test as it is still in beta, hopefully a wider beta will be released at some point in the future.

For the meantime why don’t you check out the PowerCLI Blog for more information here (Love the paperclip reference)

Continue reading →

PowerCLI: Mass provision datastore’s

At the moment I am adding around 50 datastore’s to a host, now whilst I love using the great Virtual Infrastructure Client wizard to do this after adding two of the 50 i remembered what someone said (can’t remember who)….. If you do something more than once, script it.

So guess what I did….

The following script was used to add the datastore’s from a csv file whilst I happily worked on other things.

The csv file consisted of the following:

LUNid,Hostid
101,1
221,2
331,3
451,4
521,5
661,6

etc etc, the naming convention for my datastores is SAN_HOSThostid_LUNlunid so this was easily scripted as so:

$CSVFile = "C:\Temp\Datastores.csv"
$MYESXHost = "ESX01.virtu-al.local"
$VMHBA = "vmhba2:0:"

Connect-VIServer MYVISERVER
$CSV = Import-CSV $CSVFile
$ESXHost = Get-VMHost $MYESXHost
$ESXHost |Get-VMHostStorage -RescanAllHBA
Foreach ($Item in $CSV){
  
$HostID = $Item.HostId
  
$LunID = $Item.LunID
  
Write "Creating SAN_HOST$($HostID)_LUN$($LunID)…"
  
$ESXHost |New-Datastore -Vmfs -Name "SAN_HOST$($HostID)_LUN$($LunID)" -Path "$($VMHBA)$($HostID)"
}

The New-Datastore cmdlet also has a -BlockSizeMB parameter which can be used to specify the block size of VMFS in megabytes.

All in all it took me around 10 minutes to add 50 datastore’s which I think would have taken significantly longer through the GUI.  Yet another reason to start learning PowerCLI !

PowerCLI: One-liners last 10 VMs created and removed

I was asked if it was easy enough to get a list of the last 10 VMs created in a virtual Infrastructure, the answer is yes, its a one-liner !

To list the last 10 VMs created, cloned or imported use the following:

Get-VIEvent -maxsamples 10000 |where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage -First 10

 

Or if you would like to get the last 5 VMs removed from your VI use the following:

Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name -eq "VmRemovedEvent"} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 19

As requested, here is how you can get a list of the VM’s created over the last 14 days:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) | where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage

And a list of the VMs removed over the last 14 days:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) |where {$_.Gettype().Name-eq "VmRemovedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage

PowerCLI: Number of vCPUs in a cluster

Inspired by Jason Boche’s article: http://www.boche.net/blog/index.php/2009/08/18/hidden-virtual-cpu-limit-restriction-in-esx-3-5/ and also William Lam’s Perl Script (http://communities.vmware.com/docs/DOC-10556).  I decided to re-create this in PowerCLI.

If you haven’t seen William’s scripts, I strongly suggest you check out the Perl Sample code where he stores them here: http://communities.vmware.com/community/developer/codecentral/vsphere_perl, he has been coding mad recently and turning out some really good stuff.

The PowerCLI script gives the following output:

Cluster: Production
Host: vmgesx01.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 4
Host: vmgesx02.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 3
Host: vmgesx03.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 2
Host: vmgesx04.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 5
———-
Number of vCPU in Production: 14
———-

Continue reading →

PowerCLI: Daily Report V2

Firstly I would like to thank everyone who took the time to comment on my previous Daily Report script, I really appreciate the feedback and have never had so many comments !

Now onto V2…

This one will take a while longer to run than the last script but as its a scheduled task we are not really worried about that, we are hardly going to sit there and watch it running !

I think you will agree the results are worth the wait:

What’s new

  • Bug Fixes
  • Active VMs count
  • Inactive VMs count
  • DRS Migrations count and list
  • Correct NTP Server check for each host
  • VMs stored on local datastores
  • NTP Service check for each host
  • vmkernel warning messages for each host
  • VM CPU ready over x%
Continue reading →