public/Get-D4IOTDevices.ps1
function Get-D4IOTDevices { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $HostName, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$APIKey, [Parameter(Mandatory = $false, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [bool]$Authorized, [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-Verbose -Message "$APIKey" Write-Verbose -Message "$HostName" Write-Verbose -Message "URI Formation Started..."; $strUri = "https://$HostName//api//v1//devices"; Write-Verbose -Message "Parameters Formation Started..."; $bodyContent =@{}; if($Authorized) { $bodyContent.Add("authorized", $Authorized); Write-Verbose -Message "Parameter Added authorized $Authorized" } $BaseUri=[System.Uri]$strUri; 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-D4IOTDevices $return"; return $return ; } } } |