2,187
edits
(→Script Extracts: Added "ESX Datastore to LUN Mapping (ESX4)") |
(→Script Extracts: Added "ESX Storage Events") |
||
Line 885: | Line 885: | ||
} | } | ||
</source> | </source> | ||
=== ESX Storage Events === | |||
Creates a CSV of storage events (eg path up/downs). Useful in order to be analyse storage events, for example if you need to tally up to SAN logs etc. Note the <code> get-VIEvent </code> is limited to 1000 results, which will typically get 1 - 2 days worth depending on your infrastructure. To get a longer history would require multiple calls to <code> get-VIEvent </code> using the <code>-Start</code> and <code>-Finish</code> parameters | |||
<source lang="Powershell"> | |||
$OutputFile = "ESX-EventsStorage.csv" | |||
$Results = @() | |||
$events = Get-VIEvent -MaxSamples 1000 | Where {$_.EventTypeID -like "esx.*.storage.*"} | |||
foreach ($event in $events) { | |||
$row = "" | Select Date, Host, EventID, Device, Datastore, Path | |||
$row.Date = $event.CreatedTime | |||
$row.Host = $event.Host.Name.Split(".")[0] | |||
$row.EventID = $event.EventTypeID | |||
# Allow for Argument Keys being mixed up between "problem" aka fault start and "clear" aka fault end events | |||
$row.Device = $event.Arguments[0].Value | |||
if ($row.EventID -like "esx.problem.*") { | |||
$row.Datastore = $event.Arguments[2].Value | |||
$row.Path = $event.Arguments[1].Value | |||
} elseif ($row.EventID -like "esx.clear.*") { | |||
$row.Datastore = $event.Arguments[1].Value | |||
$row.Path = $event.Arguments[2].Value | |||
} else { | |||
Write-Host "ERROR: Unexpected EventTypeID - " $row.EventID | |||
} | |||
$Results = $Results + $row | |||
} | |||
$Results | Format-Table * | |||
$Results | Export-Csv -path $OutputFile -NoTypeInformation | |||
</source> | |||
[[Category:VMware]] | [[Category:VMware]] | ||
[[Category:PowerShell]] | [[Category:PowerShell]] |