public/Get-D4IOTDeviceAlerts.ps1
function Get-D4IOTDeviceAlerts { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $HostName, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$APIKey, [Parameter(Mandatory = $false, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [int]$DeviceId ) begin { #precheck } process { Write-Verbose -Message "Starting Get-D4IOTDevices Method" try { add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" #$headers.Add("Authorization", "3fa31c74e083409dba9de80942d05ebb") $headers.Add("Authorization", "$APIKey") Write-Debug -Message "$APIKey" Write-Debug -Message "$HostName" $BaseUri=[System.Uri]"https://$HostName//api//v1//alerts"; #$jsonresponse = Invoke-RestMethod 'https://192.168.1.100//api//v1//devices' -Method 'GET' -Headers $headers $jsonresponse = Invoke-RestMethod $BaseUri -Method 'GET' -Headers $headers $jsonresponse = $jsonresponse | ConvertTo-Json return $jsonresponse; } catch { $return = $_.Exception.Message Write-Verbose $_ Write-Error "error in Get-D4IOTDeviConnections" return "Error"; } } } |