Get-OMEDeviceHWLogs.ps1
Function Get-OMEDeviceHWLogs { <# .SYNOPSIS Gets hardware logs from the specified device. .DESCRIPTION Gets hardware logs from the specified device. .PARAMETER Id Specifies Id of the device. .PARAMETER Name Specifies Name of the device. .PARAMETER AssetTag Specifies Asset Tag of the device. .PARAMETER ServiceTag Specifies Service Tag of the device. .PARAMETER Severity Query only events with the specified severity. .PARAMETER Before Specifies the date and time that this cmdlet get events that occur before. .PARAMETER After Specifies the date and time that this cmdlet get events that occur after. .PARAMETER Newest Specifies the maximum number of events that this cmdlet gets. This cmdlet gets the specified number of events, beginning with the newest event in the log. .PARAMETER Session Specifies the Session Id for the OME server. .EXAMPLE Get-OMEDeviceHWLogs -Session $session -Name server.example.com Severity Date Message -------- ---- ------- 4 02/07/2016 06:13:29 PM The power supplies are redundant. 4 08/12/2015 10:51:43 AM The chassis is closed while the power is off. 16 08/12/2015 10:51:38 AM The chassis is open while the power is off. 16 08/10/2015 09:40:23 PM Correctable memory error rate exceeded for DIMM_A7. 8 08/10/2015 09:39:58 PM Correctable memory error rate exceeded for DIMM_A7. 4 12/01/2014 05:43:19 PM Log cleared. .EXAMPLE Get-OMEDeviceGroup -Session $session -Name Paris | Get-OMEDevice -Session $Session | Gt-OMEDeviceHWLogs -Session $session -Severity Critical Severity Date Message -------- ---- ------- 16 07/12/2016 12:18:25 AM Power supply redundancy is lost. 16 07/12/2016 12:18:07 AM The power input for power supply 1 is lost. 16 07/16/2015 10:06:15 AM The chassis is open while the power is off. 16 02/25/2015 10:00:54 PM A runtime critical stop occurred. 16 08/11/2014 08:39:17 AM The PERC1 battery has failed. 16 04/29/2013 01:37:22 PM The chassis is open while the power is off. 16 06/12/2016 08:35:13 AM Power supply redundancy is lost. 16 06/12/2016 08:35:10 AM The power input for power supply 2 is lost. 16 06/12/2016 08:34:14 AM The power input for power supply 1 is lost. 16 06/12/2016 08:34:12 AM Power supply redundancy is lost. .NOTES Author: Mike Khar .LINK http://www.dell.com/support/home/us/en/04/product-support/product/dell-openmanage-essentials-v2.2/research https://$Server:$Port/api/OME.svc/$DeviceId/HWLogs/SEL #> [CmdletBinding(DefaultParametersetName="Id" )] Param( [parameter(Mandatory=$true,ParameterSetName="Id",ValueFromPipeline=$true)] $Id, [parameter(Mandatory=$true,ParameterSetName="Name")] [String]$Name, [parameter(Mandatory=$true,ParameterSetName="AssetTag")] [String]$AssetTag, [parameter(Mandatory=$true,ParameterSetName="ServiceTag")] [String]$ServiceTag, [OMESeverityType]$Severity, [datetime]$Before, [datetime]$After, [int]$Newest, $Session="OMEConnection.DefaultOMESession" ) Begin { $CurrentSession = Get-Variable -Scope Global -Name $Session -ErrorAction SilentlyContinue -ValueOnly If (!$CurrentSession) { Write-Warning "Please use Set-OMEConnection first" Break Return } else { $BaseUri="https://"+$CurrentSession.Server+":"+$CurrentSession.Port+"/api/OME.svc" } } Process { Try { If ($Id) { if (!($Id -as [int])) { $Id=$Id.Id } } if ($Name) { $Id=$(Get-OMEDevice -Session $Session -All | where {$_.Name -eq $Name}).Id } if ($AssetTag) { $Id=$(Get-OMEDevice -Session $Session -All | where {$_.AssetTag -eq $AssetTag}).Id } if ($ServiceTag) { $Id=$(Get-OMEDevice -Session $Session -All | where {$_.ServiceTag -eq $ServiceTag}).Id } if ($Id) { $uri=$BaseUri+"/Devices/$Id/HWLogs/SEL" if ($CurrentSession.Credentials) { $result = Invoke-WebRequest -Uri $uri -Credential $CurrentSession.Credentials } else { $result = Invoke-WebRequest -Uri $uri -UseDefaultCredentials } if ($result.StatusCode -ne 200) { Out-OMEException -Exception $_ return } else { Write-Debug "HTTP request: $uri HTTP status code: $($result.StatusCode)" [xml]$xml=$result.Content $result=$xml.GetSelLogsResponse.GetSelLogsResult.HardwareLogEntry if ($severity) { $result=$result | where {$_.Severity -eq $severity.value__} } if ($Before) { $result=$result | where {[datetime]$_.date -lt $Before} } if ($After) { $result=$result | where {[datetime]$_.date -gt $After} } if ($Newest) { $result=$result | Sort-Object {$_.date -as [datetime]} | select -Last $Newest } } if ($result.Message -ne "Request returned with empty logs.") { return Convert-XMLtoPSObject -xml $result -ObjectType "OME.HWLogs" } } } Catch { Out-OMEException -Exception $_ } } End{} } |