Functions/Get-IAView.ps1
Function Get-IAView { <# .SYNOPSIS Returns a list of Views in Insight Analytics. .DESCRIPTION Views are used in Insight Analytics to hold different Groups. .EXAMPLE Get-IAView -All .EXAMPLE Using Expand will include Tenant, Category, Groups and Filters with the View. Get-IAView -Expand #> [CmdletBinding(DefaultParameterSetName='Name')] Param( [Parameter(Mandatory = $true, ParameterSetName='Filter')] [String] $Filter, [Parameter(ParameterSetName='All')] [Switch] $All, [Parameter(ParameterSetName='All')] [Parameter(ParameterSetName='Id')] #[Parameter(ParameterSetName='Name')] [Switch] $Expand, [Parameter(Mandatory = $true, ParameterSetName='Id')] [String] $Id ) DynamicParam { try { $Bucket = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $AttributeList = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] $Values = (Invoke-IAQuery -QueryUrl 'Views' -Method Get).Value.Name $AttribValidateSet = New-Object System.Management.Automation.ValidateSetAttribute($Values) $AttributeList.Add($AttribValidateSet) $AttribParameter = New-Object System.Management.Automation.ParameterAttribute $AttribParameter.Mandatory = $true $AttribParameter.ParameterSetName = 'Name' $AttribParameter.Position = 0 $AttributeList.Add($AttribParameter) $ParameterName = 'Name' $Parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($ParameterName,[String], $AttributeList) $Bucket.Add($ParameterName, $Parameter) $Bucket } catch [System.Net.WebException] { $CurrentError = $_ throw [System.Net.WebException]::New('Make sure TLS1.2 is allowed!', $currentError.Exception) } catch { $CurrentError = $_ if($CurrentError.Exception.Message -like '*https:///api/Categories*'){ throw [System.ArgumentException]::New('Make sure that you are connected to the environment!', $currentError.Exception) } } } End { Foreach ($key in $PSBoundParameters.Keys) { if ($MyInvocation.MyCommand.Parameters.$key.isDynamic) { Set-Variable -Name $key -Value $PSBoundParameters.$key } } $Uri = "Views" if($Id){ $Uri += "($Id)" } if($All){} elseif($Name){ $Uri += "?&`$filter=Name eq '$Name'" } elseif ($Filter) { $Uri += "?&`$filter=$Filter" } if($Expand){ $Uri += '?$expand=*' } $response = Invoke-IAQuery -QueryUrl $Uri -Method Get if(!$Id) { if ($null -eq $response.value) { return $null } return $response.value } else{ return $response } } } |