Automated support bundles

I received an email recently from a gentleman asking if it was possible to export the support bundles for each host on a daily basis, this can be useful for not only having an archive of your system logs to help resolve problems and work out when they started but also useful for auditing purposes.

At the moment he was doing this manually every day by using the virtual infrastructure client as can be seen below – you can imagine how long this was taking !

Exporting the logs from the vCenter Client

image

1.  Select the File menu and then Export, Export System Logs…

SNAGHTML3030b74

2.  Select the hosts which you want to download the system logs for and click OK

So how can we automate this ?

Luckily with the Get-Log cmdlet VMware gave us a –bundle parameter which allows us to produce these support bundles, the following code can be run as a scheduled task and simply creates a folder structure to save the bundles for each host every day, the folder layout is set as follows:

RootFolder \ Date \ Hostname \ Supportfile.tgz

This can be seen from the below screenshot:

Folder Structure

The code for this script can be seen below, it is also only 10 lines of code – man I love PowerShell !

You can obviously change the root folder by altering the first line.

The Code

Connect-VIServer MYvCenter
$RootFolder = "C:\Support\"
Get-VMHost | Foreach {
	Write-Host "Collecting Support Bundle for $($_.Name)"
	$Date = Get-Date -f yyyy-MM-dd
	$Folder = $RootFolder + $Date + "\$($_.Name)\"
	If (-not (Test-Path $Folder)) {
		MD $Folder | Out-Null
	}
	Get-Log -VMHost $_ -Bundle -DestinationPath $Folder
}

7 thoughts on “Automated support bundles

  1. SeaCros

    If i automate it via script can i narrow it down to the cluster level of the logs that I would like to capture? My environment is very large and I would like to spread the process out over a few hours.
    Thanks

  2. Kelly Dare

    I am having the same issue as Derek, I see the “generate logs” task in Virtual Center, but I never get further than “In Progress” on the VC console. On my command window where the script is running I see “Collecting Support Bundle” but nothing else progresses.

  3. Derek Ross

    Hey Alan,

    Roughly how long should this script take to run? I’m just testing the command “get-log host -bundle -destinationpath c:\blah” inside a PS window. It says at the top ‘Generate system logs bundles with 0% compete. After 15 mins or so I just ctrl-c it since it doesn’t progress forward.

    Thoughts?

  4. Hal Rottenberg

    @David, since Connect-ViServer can use passthrough authentication, it is super easy to paste the above script into a file, then create a Windows scheduled task (probably on a utility server in your environment) to run the file. Provide the scheduled task with credentials with permission to read logs from vCenter, and away you go.

  5. Virtu-Al

    You can run this from anywhere you have PowerCLI installed, PowerCLI is just another way of hooking into vCenter, much like the vCenter Client can be installed anywhere that has IP access to the vCenter, so can PowerCLI.

    I have amended the script to add the Connect-ViServer cmdlet in it, your right, I shouldn’t assume that people know how to do this ! – Thanks for keeping me honest 😉

    Alan

  6. David R

    That’s great, I’m curious to know where you are running this script from, the VCenter desktop? What about authentication etc?

Leave a Reply to Sean

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.