Task Data Mining – An improved Get-Task

Quite frequently there are questions in the VMTN PowerCLI Community for scripts that report on the tasks that ran in a vSphere environment.

The PowerCLI pssnapin provides a Get-Task cmdlet, but that only provides information about the recent tasks. An alternative is to use the Get-VIEvent cmdlet and extract all the TaskEvent entries.

But why not use the TaskHistoryCollector and it’s methods ? It provides many filtering options, and since this filtering is done in vSphere itself, this way of working is inherently much faster than using a filter in your script.

In analogy with the Get-VIEventPlus function, I published in my Get the vMotion/svMotion history post, here is the Get-TaskPlus function !

Update February 13th 2020

  • Added logic to break out of do-while loop and destroy the TaskCollector to avoid issues with max 32 collectors

Continue reading Task Data Mining – An improved Get-Task

HA VM failover tracking

Another interesting question in the PowerCLI Community today.
David wanted to know if it was possible to track which VMs had been failed over to another ESXi host by HA.
With the Get-VIEventPlus function from my Get the vMotion/svMotion history post it is easy to get that informatiom from the Tasks and Events that are kept in the vCenter database.

HA-failover

But which event to look for ?

Continue reading HA VM failover tracking

Get the vMotion/svMotion history

The availability of vMotion and svMotion, provided you have a license that allows it, in vSphere are some of its key features.

The DRS and SDRS functionality will use vMotion and svMotion to better use the available resources.

And you as a vSphere administrator can use it to facilitate your work. Just think of how easy patching or datastorecluster maintenance becomes with the help of these two features.
But as an administrator you want to be able to report on what vMotion and svMotion have been doing over a specific time interval in your vSphere environment.

In the past I already provided a vMotion reporting tool in Events – Part 8 – vMotion history, but now it was time to provide a universal (s)vMotion reporting feature.

motion-reports

Update October 29th 2013: added additional parameters to the Get-VIEventPlus function

  • User: one or more users for which to return the events
  • System: a switch to return all system user events
  • ScheduledTask: return all events for a specific Scheduled Task

Update February 10th 2014: it’s always nice to see another implementation based on one of your scripts. The Opvizor solution will soon contain this function, see Dennis Zimmer‘s post called Storage vMotion Activities Report ! Continue reading Get the vMotion/svMotion history

Alarm actions – enable – disable – report

Another post triggered by a question in the VMTN PowerCLI community. The user wanted to know how he could create a report that showed for which vSphere entities the alarm actions were disabled.

To set the stage, a short overview of what this is all about. In vSphere you can, since vSphere 4, disable and enable alarm actions for all the managed entities. This option is available from the vSphere client

alarm-action-old-client

and from the vSphere Web client.

alarm-action-web-client

But how to automate these actions, and more importantly in this case, how to report on the active settings ? Like always PowerCLI to the rescue.

Continue reading Alarm actions – enable – disable – report

dvSwitch scripting – Part 13 – Export/Restore Config

One of the exciting new dvSwitch features in vSphere 5.1 is the ability to export and restore a dvSwitch configuration. This new feature is only available through the vSphere Web Client.

On Hypervisor.fr, a blog you should have in your RSS reader, there were already posts on how to configure the dvSwitch healthcheck and how to do a dvSwitch configuration rollback from PowerCLI. But till now, as far as I know, there were no functions to provide the dvSwitch export/restore functionality.

dvSw-export-import

Time to make this useful functionality available for the “PowerCLI automation crowd” 😉

Continue reading dvSwitch scripting – Part 13 – Export/Restore Config

Automate your SDRS Anti-Affinity rules

One of the hot new features in vSphere 5 was the introduction of SDRS. And with SDRS came the concept of affinity rules for VMs and VMDKs. Cormac, aka @VMwareStorage, posted a nice overview of the SDRS affinity rules in Storage DRS Affinity & Anti-Affinity Rules.

choice and directions signs

Since then several posts have appeared on the subject of SDRS affinity rules.  To list just a few:

Currently there are no PowerCLI cmdlets to define the inter- and intra-vm anti-affinity rules for SDRS. After a question in the VMTN PowerCLI Community I decided to write a function. This function will allow you to automate the creation of the SDRS anti-affinity rules.

Continue reading Automate your SDRS Anti-Affinity rules

Find free SCSI LUNs

Another post that comes from a VMTN PowerCLI Community question. Jeff wanted to find the free SCSI LUNs in his environment.
While answering that thread I was amazed there was no PowerCLI function written yet to provide this functionality. At least that was what my friend Google told me 😉

Since there exists a SDK method that makes retrieving free SCSI LUNs quite easy, the function I came up with isn’t too complex.

But it should help you in further automating the setup of your datastores.

Continue reading Find free SCSI LUNs

Export-Xlsx, the sequel, and ordered data

Some time ago I published the Export-Xls function to the world in my Beyond Export-Csv: Export-Xls post. And it has been one of the more popular functions on my blog.

PS-2-Excel

Just before Christmas 2012 I got a comment from Gilbert where he informed me that he had written an Export-Xlsx function and had borrowed some of the parameters that were on the original Export-Xls function. We exchanged a couple of emails with suggestions and ideas, and yesterday the finalised Export-Xlsx function was posted on Gilbert’s ITPilgrims blog (which you should follow btw) in his Export-Xlsx post.

In this post I will publish this new Export-Xlsx function with some annotations, and I will also show how you can now export your data in the order you want, provided you’re using PowerShell v3.

Continue reading Export-Xlsx, the sequel, and ordered data

Game of Nines – VM Uptime Report

The end of the year is near again. Time to plan for the new, but also a time to look back on what was there in the past year.

Your vSphere environment is no different. It is time to produce some of those dreaded year reports that will show you how your environment has been doing. And one of the aspects a lot of people are very keen about, is the number 9 game 😉

Game-of-Nines

What was the uptime of the VMs you had running ?

The question popped up on several occasions in the PowerCLI Community as well. So I guess I was not the only one that was looking for a way to calculate the uptime of Virtual Machines.

Bug alert ?: it seems that the PerformanceManager handles vMotions in a strange way. After a vMotion the sys.uptime.latest is reset to 0 (zero). That is understandable, since the VM is now running on a different ESXi host. But it seems that the aggregated metric do not add up all the sys.uptime.latest metrics from different ESXi hosts. So when you use DRS or do vMotions yourself, the produced report will have some serious flaws !

Continue reading Game of Nines – VM Uptime Report

Monitor the size of your vDisks

In a recent thread on the VMTN PowerCLI Community someone asked if it is possible to get historical hard disk statistics. I referred the user to my Datastore usage statistics post, where I showed how to use the “disk” metrics to get that information.

But getting the individual vDisk statistics is a bit more tricky compared to getting the datastore statistics, as I showed in that post. The “disk” metrics hold the information, but the Instance that points to the MoRef value of a VM makes it a bit more tricky to retrieve.

Be forewarned, the “disk” metrics hold usage data for all the vDisks that a specific VM has on a specific datastore. You will not be able to get individual vDisk statistics, unless the vDisks are stored on different datastores !

On the positive side, the “disk” metrics will allow you to see how your vDisks increase in size over time. For your Thick vDisks that increase will be by expanding them, and for your Thin vDisks it will also show the natural growth.

Continue reading Monitor the size of your vDisks