public/Get-D4IOTDeviceAlerts.ps1
function Get-D4IOTDeviceAlerts { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $HostName, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$APIKey, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$AlertState, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [int]$AlertFromTime, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [int]$AlertToTime, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$AlertType, [Parameter(Mandatory = $false, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [bool]$IgnoreSSL ) begin { #precheck } process { Write-Verbose -Message "Starting Get-D4IOTDevices Method" try { Write-Verbose -Message "Header Formation Started..." $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Authorization", "$APIKey") Write-Debug -Message "$APIKey" Write-Debug -Message "$HostName" Write-Verbose -Message "URI Formation Started..." $BaseUri=[System.Uri]"https://$HostName//api//v1//alerts"; Write-Verbose -Message "Parameters Formation Started..."; $bodyContent =@{}; if($AlertState -ne $null) { $bodyContent.Add("state", $AlertState); Write-Verbose -Message "Parameter Added state $AlertState"; } if($AlertFromTime -gt 0) { $bodyContent.Add("fromTime", $AlertFromTime); Write-Verbose -Message "Parameter Added fromTime $AlertFromTime"; } if($AlertToTime -gt 0) { $bodyContent.Add("toTime", $AlertFromTime); Write-Verbose -Message "Parameter Added toTime $AlertFromTime"; } if($AlertType -ne $null) { $bodyContent.Add("type", $AlertType); Write-Verbose -Message "Parameter Added type $AlertType"; } if($IgnoreSSL) { $jsonresponse = Invoke-RestMethod $BaseUri -Method 'GET' -Headers $headers -Body $bodyContent -SkipCertificateCheck } else { $jsonresponse = Invoke-RestMethod $BaseUri -Method 'GET' -Headers $headers -Body $bodyContent } $jsonresponse = $jsonresponse | ConvertTo-Json return $jsonresponse; } catch { $return = $_.Exception.Message; Write-Verbose $_; Write-Error "Error in Get-D4IOTDeviceAlerts $return"; return $return ; } } } |