Remove-OMEAlert.ps1
Function Remove-OMEAlert { <# .SYNOPSIS Removes event with specified Id from the Alert logs. .DESCRIPTION Removes event with specified Id from the Alert logs. Returns status of the operation. .PARAMETER AlertId Specifies Alert Id. .PARAMETER Session Specifies the Session Id for the OME server. .EXAMPLE Remove-OMEAlert -Session $session -AlertId -2147472351 StatusCode : 200 StatusDescription : OK Content : <ccaba800c3274c20d176c464ceb14e282 xmlns="http://schemas.datacontract.org/2004/07/A" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Messages i:nil="true"/><Result>true</Result></ccaba800c3274c20... RawContent : HTTP/1.1 200 OK Persistent-Auth: false Access-Control-Allow-Origin: * Content-Length: 218 Cache-Control: private Content-Type: application/xml; charset=utf-8 Date: Sun, 11 Sep 2016 20:26:39 GMT... Forms : {} Headers : {[Persistent-Auth, false], [Access-Control-Allow-Origin, *], [Content-Length, 218], [Cache-Control, private]...} Images : {} InputFields : {} Links : {} ParsedHtml : mshtml.HTMLDocumentClass RawContentLength : 218 .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/Alerts/$AlertId #> [CmdletBinding(DefaultParametersetName="AlertId" )] Param( [parameter(Mandatory=$true,ParameterSetName="AlertId",ValueFromPipeline=$true)] $AlertId, $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 ($AlertId -is [PSObject]) { $AlertId=$AlertId.Id if (!$AlertId) { return } } $uri=$BaseUri+"/Alerts/$AlertId" if ($CurrentSession.Credentials) { $result = Invoke-WebRequest -Uri $uri -Credential $CurrentSession.Credentials -Method Delete -ErrorAction SilentlyContinue } else { $result = Invoke-WebRequest -Uri $uri -UseDefaultCredentials -Method Delete -ErrorAction SilentlyContinue } if ($result.StatusCode -ne 200) { Out-OMEException -Exception $_ return } else { Write-Debug "HTTP request: $uri HTTP status code: $($result.StatusCode)" } return $result } Catch { Out-OMEException -Exception $_ } } End{} } |