PSInsight.psm1
function New-InsightHeaders { <# .SYNOPSIS Generate Insight headers. .EXAMPLE $Headers = New-InsightHeaders -ApiKey $InsightApiKey .OUTPUTS Generic dictionary. #> param ( [Parameter(Mandatory = $true)] [string]$InsightApiKey ) Write-Verbose 'Generating Headers' $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $Headers.Add('content-type' , 'application/json') $Headers.Add('authorization', 'bearer ' + $InsightApiKey) Write-Output $Headers } function Get-InsightIcons { <# .SYNOPSIS Resource to find global Icons in Insight. .DESCRIPTION Resource to find global Icons in Insight. .PARAMETER Full If full switch is used then property url16 is returned .PARAMETER InsightApiKey The Api key. .OUTPUTS If switch 'Full' is used id name url16 -- ---- ----- 1 3D Printer /rest/insight/1.0/icon/1/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLm... 2 AV Receiver /rest/insight/1.0/icon/2/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLm... if switch 'Full' is not used id name -- ---- 1 3D Printer 2 AV Receiver 3 Active Directory 4 Administrative Tools 5 Agreement .LINK https://documentation.mindville.com/display/ICV811/Icons+-+REST .EXAMPLE Get-InsightIcons -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey, [switch]$Full = $False ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/icon/global" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } if ($Full) { Write-Output $response } else { Write-Output $response | Select id,name } } } function Get-InsightObjectSchema { <# .SYNOPSIS Resource to find object schemas in Insight for a specific object schema. The object schemas are responded in a list. .DESCRIPTION Resource to find object schemas in Insight for a specific object schema. The object schemas are responded in a list. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 3 name : MyObjectSchema objectSchemaKey : MOS status : Ok description : Object Schema created : 2020-09-16T00:50:30.919Z updated : 2020-09-16T01:56:33.430Z objectCount : 0 objectTypeCount : 1 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+schema .EXAMPLE Get-InsightObjectSchema -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objectschema/list" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } If (!($response.objectschemas)) { Write-Verbose "No object schemas found" } Else { If($response.objectschemas){ $response.objectschemas } else{ $response } } } } function New-InsightObjectSchema { <# .SYNOPSIS Resource to create an object schema in Insight. .DESCRIPTION Resource to create an object schema in Insight. .PARAMETER Name The object schema name. .PARAMETER ObjectSchemaKey The object schema key. .PARAMETER Description The object schema description. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : CMDB objectSchemaKey : ABC status : Ok description : My Object Schema created : 2020-09-16T00:22:31.948Z updated : 2020-09-16T00:22:31.963Z objectCount : 0 objectTypeCount : 0 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+schema .EXAMPLE New-InsightObjectSchema -Name "MyObjectSchema" -ObjectSchemaKey "NAS" -Description "My New Object Schema" -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ObjectSchemaKey, [Parameter(Mandatory = $false)] [string]$Description, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objectschema/create" $RequestBody = @{ 'name' = $Name 'objectSchemaKey' = $ObjectSchemaKey } $RequestBody.Add('description',$Description) $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method POST } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function Remove-InsightObjectSchema { <# .SYNOPSIS Resource to delete an object schema in Insight. .DESCRIPTION Resource to delete an object schema in Insight. .PARAMETER ID The object schema ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : CMDB objectSchemaKey : ABC status : Ok description : My Object Schema created : 2020-09-16T00:22:31.948Z updated : 2020-09-16T00:22:31.963Z objectCount : 0 objectTypeCount : 0 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+schema .EXAMPLE Remove-InsightObjectSchema -ID 1 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objectschema/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method Delete } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function Set-InsightObjectSchema { <# .SYNOPSIS Resource to update an object schema in Insight. .DESCRIPTION Resource to update an object schema in Insight. .PARAMETER ID The id of the schema. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : MyObjectSchema objectSchemaKey : MOS status : Ok description : My New Object Schema - Updated created : 2020-09-16T00:22:31.948Z updated : 2020-09-16T00:22:31.963Z objectCount : 0 objectTypeCount : 0 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+schema .EXAMPLE Set-InsightObjectSchema -ID 3 -Name "MyObjectSchema" -ObjectSchemaKey "MOS" -Description "My New Object Schema - Updated" -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$ID, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ObjectSchemaKey, [Parameter(Mandatory = $false)] [string]$Description, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objectschema/$($ID)" $RequestBody = @{ 'name' = $Name 'objectSchemaKey' = $ObjectSchemaKey } If($Description){ $RequestBody.Add('description',$Description) } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method PUT } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function Get-InsightObjectTypeAttributes { <# .SYNOPSIS Resource to find Object Type Attributes for a specified Object Type in Insight. .DESCRIPTION Resource to find Object Type Attributes for a specified Object Type in Insight. .PARAMETER ID The Object Type ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 7 objectType : @{id=2; name=My Object Type; type=0; description=A Sample Object Type; icon=; position=0; created=2020-09-16T07:14:02.118Z; updated=2020-09-16T07:14:02.118Z; objectCount=0; objectSchemaId=3; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False} name : Key label : False type : 0 defaultType : @{id=0; name=Text} editable : False system : True sortable : True summable : False indexed : True minimumCardinality : 1 maximumCardinality : 1 removable : False hidden : False includeChildObjectTypes : False uniqueAttribute : False options : position : 0 id : 8 objectType : @{id=2; name=My Object Type; type=0; description=A Sample Object Type; icon=; position=0; created=2020-09-16T07:14:02.118Z; updated=2020-09-16T07:14:02.118Z; objectCount=0; objectSchemaId=3; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False} name : Name label : True type : 0 description : The name of the object defaultType : @{id=0; name=Text} editable : True system : False sortable : True summable : False indexed : True minimumCardinality : 1 maximumCardinality : 1 removable : False hidden : False includeChildObjectTypes : False uniqueAttribute : False options : position : 1 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+type+attributes .EXAMPLE Get-InsightObjectTypeAttributes -ID 2 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttype/$($ID)/attributes" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function New-InsightObjectTypeAttributes { <# .SYNOPSIS Resource to create an object type attribute in Insight. .DESCRIPTION Resource to create an object type attribute in Insight. .PARAMETER Name The name. .PARAMETER Type The type. ["Default", "Object", "User", "Confluence", "Group", "Status"] .PARAMETER ParentObjectTypeId The Object type ID of the Parent .PARAMETER defaultType The default type id. Dynamic Parameter if 'Type' is 'Default' ["Text", "Integer", "Boolean", "Double", "Date", "Time", "Date_Time", "URL", "Email", "TextArea", "Select", "IP_Address"] .PARAMETER typeValue The referenced object type id. Dynamic Parameter if 'Type' is 'Object' .PARAMETER typeValueMulti The JIRA groups to restrict selection. Dynamic Parameter if 'Type' is 'User' .PARAMETER additionalValue. Dynamic Parameter if 'Type' is 'Object','URL' or 'Confluence' URL: DISABLED, ENABLED OBJECT: Reference Type Id User: SHOW_PROFILE, HIDE_PROFILE Confluence: Confluence Space Id .PARAMETER minimumCardinality. Dynamic Parameter if 'Type' is 'Email','Select','Object','User','Group','Version','Project' The minimum cardinality (default 0) .PARAMETER maximumCardinality. Dynamic Parameter if 'Type' is 'Email','Select','Object','User','Group','Version','Project' The maximum cardinality (default 1) .PARAMETER suffix If suffix on value types (Integer, Float). Dynamic Parameter if 'Default Type' is 'Integer' or 'Float' .PARAMETER includeChildObjectTypes If objects should be valid for object type children. Dynamic Parameter if 'Type' is 'Object' .PARAMETER iql If objects should be filtered by IQL. Dynamic Parameter if 'Type' is 'Object' .PARAMETER uniqueAttribute If the attribute should be unique (true, false) .PARAMETER summable If a sum should be shown in list view (true, false). Dynamic Parameter if 'Default Type' is 'Integer' or 'Float' .PARAMETER regexValidation. Dynamic Parameter if 'Type' is 'Text' or 'Email' If a regex validation should apply .PARAMETER options. Dynamic Parameter if 'Type' is 'Options' The options for the attribute in comma separate list .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 6 name : Test Attribute label : False type : 0 defaultType : @{id=0; name=Text} editable : True system : False sortable : True summable : False indexed : True minimumCardinality : 0 maximumCardinality : 1 removable : True hidden : False includeChildObjectTypes : False uniqueAttribute : False options : position : 4 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+type+attributes .EXAMPLE New-InsightObjectTypeAttributes -Name "Test Attribute" -Type Default -DefaultType Text -ObjectTypeId 1 -InsightApiKey $InsightApiKey New-InsightObjectTypeAttributes -Name "Email Address" -Type Default -DefaultType Email -ParentObjectTypeId 1 -InsightApiKey $InsightApiKey New-InsightObjectTypeAttributes -Name "Link to Parent" -Type Object -typeValue 2 -ParentObjectTypeId 1 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $true)] [ValidateSet("Default", "Object", "User", "Confluence", "Group", "Status")] [string]$Type, [Parameter(Mandatory = $false)] [Alias('ObjectTypeId')] [int]$ParentObjectTypeId, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) DynamicParam { # Create a new dictionary to contain all the dynamic parameters $paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary if ($Type -like "Default") { #region DefaultType #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date_Time", "URL", "Email", "TextArea", "Select", "IP_Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) $attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $DefaultType_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("DefaultType", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("DefaultType", $DefaultType_dynParam) #endregion DefaultType } if ($DefaultType -like "Integer" -or $DefaultType -like "Float") { #region suffix #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $suffix_attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $suffix_attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $suffix_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("suffix", [STRING], $suffix_attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("suffix", $suffix_dynParam) #endregion suffix #region summable #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("True", "False") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) $attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $summable_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("summable", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("summable", $summable_dynParam) #endregion summable } if ($Type -like "Object") { #region typeValue #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $typeValue_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("typeValue", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("typeValue", $typeValue_dynParam) #endregion typeValue #region includeChildObjectTypes #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $includeChildObjectTypes_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("includeChildObjectTypes", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("includeChildObjectTypes", $includeChildObjectTypes_dynParam) #endregion includeChildObjectTypes #region iql #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $iql_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("iql", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("iql", $iql_dynParam) #endregion iql } if ($Type -like "User") { #region typeValueMulti #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $typeValueMulti_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("typeValueMulti", [ARRAY], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("typeValueMulti", $typeValueMulti_dynParam) #endregion typeValueMulti } if ($Type -like "Object" -or $Type -like "URL" -or $Type -like "Confluence") { #region additionalValue #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" if ($Type -like "Object") { $attributes.Mandatory = $true } else { $attributes.Mandatory = $false } # Create the ValidateSet list if ($Type -like "URL") { $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("DISABLED", "ENABLED") } if ($Type -like "User") { $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("SHOW_PROFILE", "HIDE_PROFILE") } #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $additionalValue_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("additionalValue", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("additionalValue", $additionalValue_dynParam) #endregion additionalValue } if ($Type -like "Email" -or $Type -like "Select" -or $Type -like "Object" -or $Type -like "User" -or $Type -like "Group" -or $Type -like "Version" -or $Type -like "Project") { #region minimumCardinality #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $minimumCardinality_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("minimumCardinality", [INT], $attributeCollection) $PSBoundParameters["minimumCardinality_dynParam"] = 0 # Add Parameter to the Dictionary collection $paramDictionary.Add("minimumCardinality", $minimumCardinality_dynParam) #endregion minimumCardinality #region maximumCardinality #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $maximumCardinality_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("maximumCardinality", [INT], $attributeCollection) $PSBoundParameters["maximumCardinality_dynParam"] = 1 # Add Parameter to the Dictionary collection $paramDictionary.Add("maximumCardinality", $maximumCardinality_dynParam) #endregion maximumCardinality } if ($Type -like "Text" -or $Type -like "Email") { #region regexValidation #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $regexValidation_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("regexValidation", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("regexValidation", $regexValidation_dynParam) #endregion regexValidation } if ($Type -like "Options") { #region options #Create the base DynamicParam attributes #The options for the attribute in comma separate list - Might need to add script validation or use .join(",") $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $options_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("options", [ARRAY], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("options", $options_dynParam) #endregion options } #Return all the dynamic parameters inside the dictionary return $paramDictionary } begin { # Translate the Object Type Name to the Object Type ID switch ($Type) { "Default" { $objectTypeID = "0" } "Object" { $objectTypeID = "1" } "User" { $objectTypeID = "2" } "Confluence" { $objectTypeID = "3" } "Group" { $objectTypeID = "4" } "Status" { $objectTypeID = "7" } } # Translate the Default Object Type Name to the Default Object Type ID switch ($PSBoundParameters["DefaultType"]) { "Text" { $DefaultTypeID = 0 } "Integer" { $DefaultTypeID = "1" } "Boolean" { $DefaultTypeID = "2" } "Double" { $DefaultTypeID = "3" } "Date" { $DefaultTypeID = "4" } "Time" { $DefaultTypeID = "5" } "Date Time" { $DefaultTypeID = "6" } "URL" { $DefaultTypeID = "7" } "Email" { $DefaultTypeID = "8" } "Textarea" { $DefaultTypeID = "9" } "Select" { $DefaultTypeID = "10" } "IP Address" { $DefaultTypeID = "11" } } #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttypeattribute/$($ParentObjectTypeId)" #Create default Hash $RequestBody = @{ name = $Name } #Add required attributes to the hash for all Object Types except Default switch ($Type) { { @("Object", "Confluence") -contains $_ } { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValue", $PSBoundParameters["typeValue"]) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "User" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValueMulti", $PSBoundParameters["typeValueMulti"]) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Group" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Status" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValueMulti", $PSBoundParameters["typeValueMulti"]) } } #Add required attributes to the hash for all Object Type "Default" switch ($PSBoundParameters["DefaultType"]) { { @("Text", "Integer", "Boolean", "Double", "Date", "Date_Time", "Email", "TextArea", "IP_Address") -contains $_ } { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) } "URL" { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Select" { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) $RequestBody.Add("options", $PSBoundParameters["options"]) } } # Add all the aditional Attributes. if ($uniqueAttribute) { $RequestBody.Add("uniqueAttribute", $UniqueAttribute) } if ($PSBoundParameters["minimumCardinality"]) { $RequestBody.Add("minimumCardinality", $PSBoundParameters["minimumCardinality"]) } if ($PSBoundParameters["maximumCardinality"]) { $RequestBody.Add("maximumCardinality", $PSBoundParameters["maximumCardinality"]) } if ($PSBoundParameters["suffix"]) { $RequestBody.Add("suffix", $PSBoundParameters["suffix"]) } if ($PSBoundParameters["includeChildObjectTypes"]) { $RequestBody.Add("includeChildObjectTypes", $PSBoundParameters["includeChildObjectTypes"]) } if ($PSBoundParameters["iql"]) { $RequestBody.Add("iql", $PSBoundParameters["iql"]) } if ($PSBoundParameters["summable"]) { $RequestBody.Add("summable", $PSBoundParameters["summable"]) } if ($PSBoundParameters["regexValidation"]) { $RequestBody.Add("regexValidation", $PSBoundParameters["regexValidation"]) } if ($PSBoundParameters["options"]) { $RequestBody.Add("options", $PSBoundParameters["options"]) } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method POST } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Remove-InsightObjectTypeAttributes { <# .SYNOPSIS Resource to delete an object type attribute in Insight. .DESCRIPTION Resource to delete an object type attribute in Insight. .PARAMETER ID The Object Type Attribute ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS No output from API .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+type+attributes .EXAMPLE Remove-InsightObjectTypeAttributes -ID 11 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttypeattribute/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method DELETE } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Set-InsightObjectTypeAttributes { <# .SYNOPSIS Resource to update an object type attribute in Insight. .DESCRIPTION Resource to update an object type attribute in Insight. .PARAMETER Name The name. .PARAMETER Type The type. ["Default", "Object", "User", "Confluence", "Group", "Status"] .PARAMETER ParentObjectTypeId The Object type ID of the Parent .PARAMETER defaultType The default type id. Dynamic Parameter if 'Type' is 'Default' ["Text", "Integer", "Boolean", "Double", "Date", "Time", "Date_Time", "URL", "Email", "TextArea", "Select", "IP_Address"] .PARAMETER typeValue The referenced object type id. Dynamic Parameter if 'Type' is 'Object' .PARAMETER typeValueMulti The JIRA groups to restrict selection. Dynamic Parameter if 'Type' is 'User' .PARAMETER additionalValue. Dynamic Parameter if 'Type' is 'Object','URL' or 'Confluence' URL: DISABLED, ENABLED OBJECT: Reference Type Id User: SHOW_PROFILE, HIDE_PROFILE Confluence: Confluence Space Id .PARAMETER minimumCardinality. Dynamic Parameter if 'Type' is 'Email','Select','Object','User','Group','Version','Project' The minimum cardinality (default 0) .PARAMETER maximumCardinality. Dynamic Parameter if 'Type' is 'Email','Select','Object','User','Group','Version','Project' The maximum cardinality (default 1) .PARAMETER suffix If suffix on value types (Integer, Float). Dynamic Parameter if 'Default Type' is 'Integer' or 'Float' .PARAMETER includeChildObjectTypes If objects should be valid for object type children. Dynamic Parameter if 'Type' is 'Object' .PARAMETER iql If objects should be filtered by IQL. Dynamic Parameter if 'Type' is 'Object' .PARAMETER uniqueAttribute If the attribute should be unique (true, false) .PARAMETER summable If a sum should be shown in list view (true, false). Dynamic Parameter if 'Default Type' is 'Integer' or 'Float' .PARAMETER regexValidation. Dynamic Parameter if 'Type' is 'Text' or 'Email' If a regex validation should apply .PARAMETER options. Dynamic Parameter if 'Type' is 'Options' The options for the attribute in comma separate list .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 30 name : A different name then before label : False type : 0 defaultType : @{id=0; name=Text} editable : True system : False sortable : True summable : False indexed : True minimumCardinality : 0 maximumCardinality : 1 removable : True hidden : False includeChildObjectTypes : False uniqueAttribute : False options : position : 4 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+type+attributes .EXAMPLE Set-InsightObjectTypeAttributes -ParentObjectTypeId 2 -objectTypeAttributeId 30 -Name "A different name then before" #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [Alias('ObjectTypeId')] [int]$ParentObjectTypeId, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$objectTypeAttributeId, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $false)] [string]$Name, [Parameter(Mandatory = $false)] [ValidateSet("Default", "Object", "User", "Confluence", "Group", "Status")] [string]$Type, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey = $Global:InsightAPIKey ) DynamicParam { # Create a new dictionary to contain all the dynamic parameters $paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary if ($Type -like "Default") { #region DefaultType #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date_Time", "URL", "Email", "TextArea", "Select", "IP_Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) $attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $DefaultType_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("DefaultType", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("DefaultType", $DefaultType_dynParam) #endregion DefaultType } if ($DefaultType -like "Integer" -or $DefaultType -like "Float") { #region suffix #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $suffix_attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $suffix_attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $suffix_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("suffix", [STRING], $suffix_attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("suffix", $suffix_dynParam) #endregion suffix #region summable #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $true # Create the ValidateSet list $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("True", "False") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) $attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $summable_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("summable", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("summable", $summable_dynParam) #endregion summable } if ($Type -like "Object") { #region typeValue #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $typeValue_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("typeValue", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("typeValue", $typeValue_dynParam) #endregion typeValue #region includeChildObjectTypes #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $includeChildObjectTypes_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("includeChildObjectTypes", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("includeChildObjectTypes", $includeChildObjectTypes_dynParam) #endregion includeChildObjectTypes #region iql #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $iql_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("iql", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("iql", $iql_dynParam) #endregion iql } if ($Type -like "User") { #region typeValueMulti #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $typeValueMulti_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("typeValueMulti", [ARRAY], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("typeValueMulti", $typeValueMulti_dynParam) #endregion typeValueMulti } if ($Type -like "Object" -or $Type -like "URL" -or $Type -like "Confluence") { #region additionalValue #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list if ($Type -like "URL") { $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("DISABLED", "ENABLED") } if ($Type -like "User") { $attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("SHOW_PROFILE", "HIDE_PROFILE") } #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $additionalValue_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("additionalValue", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("additionalValue", $additionalValue_dynParam) #endregion additionalValue } if ($Type -like "Email" -or $Type -like "Select" -or $Type -like "Object" -or $Type -like "User" -or $Type -like "Group" -or $Type -like "Version" -or $Type -like "Project") { #region minimumCardinality #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $minimumCardinality_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("minimumCardinality", [INT], $attributeCollection) $PSBoundParameters["minimumCardinality_dynParam"] = 0 # Add Parameter to the Dictionary collection $paramDictionary.Add("minimumCardinality", $minimumCardinality_dynParam) #endregion minimumCardinality #region maximumCardinality #The JIRA groups to restrict selection #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $maximumCardinality_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("maximumCardinality", [INT], $attributeCollection) $PSBoundParameters["maximumCardinality_dynParam"] = 1 # Add Parameter to the Dictionary collection $paramDictionary.Add("maximumCardinality", $maximumCardinality_dynParam) #endregion maximumCardinality } if ($Type -like "Text" -or $Type -like "Email") { #region regexValidation #Create the base DynamicParam attributes $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $regexValidation_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("regexValidation", [STRING], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("regexValidation", $regexValidation_dynParam) #endregion regexValidation } if ($Type -like "Options") { #region options #Create the base DynamicParam attributes #The options for the attribute in comma separate list - Might need to add script validation or use .join(",") $attributes = new-object System.Management.Automation.ParameterAttribute $attributes.ParameterSetName = "__AllParameterSets" $attributes.Mandatory = $false # Create the ValidateSet list #$attributesValidate = New-Object System.Management.Automation.ValidateSetAttribute @("Text", "Integer", "Boolean", "Double", "Date", "Time", "Date Time", "URL", "Email", "Text Area", "Select", "IP Address") # Add the Base Attributes and the Validated list attributes to a collection $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] $attributeCollection.Add($attributes) #$attributeCollection.Add($attributesValidate) #Create a new object with the Name, Type, and attributes collection. $options_dynParam = new-object -Type System.Management.Automation.RuntimeDefinedParameter("options", [ARRAY], $attributeCollection) # Add Parameter to the Dictionary collection $paramDictionary.Add("options", $options_dynParam) #endregion options } #Return all the dynamic parameters inside the dictionary return $paramDictionary } begin { # Translate the Object Type Name to the Object Type ID switch ($Type) { "Default" { $objectTypeID = "0" } "Object" { $objectTypeID = "1" } "User" { $objectTypeID = "2" } "Confluence" { $objectTypeID = "3" } "Group" { $objectTypeID = "4" } "Status" { $objectTypeID = "7" } } # Translate the Default Object Type Name to the Default Object Type ID switch ($PSBoundParameters["DefaultType"]) { "Text" { $DefaultTypeID = 0 } "Integer" { $DefaultTypeID = "1" } "Boolean" { $DefaultTypeID = "2" } "Double" { $DefaultTypeID = "3" } "Date" { $DefaultTypeID = "4" } "Time" { $DefaultTypeID = "5" } "Date Time" { $DefaultTypeID = "6" } "URL" { $DefaultTypeID = "7" } "Email" { $DefaultTypeID = "8" } "Textarea" { $DefaultTypeID = "9" } "Select" { $DefaultTypeID = "10" } "IP Address" { $DefaultTypeID = "11" } } #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttypeattribute/$($ParentObjectTypeId)/$($objectTypeAttributeId)" #Create default Hash $RequestBody = @{ name = $Name } #Add required attributes to the hash for all Object Types except Default switch ($Type) { { @("Object", "Confluence") -contains $_ } { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValue", $PSBoundParameters["typeValue"]) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "User" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValueMulti", $PSBoundParameters["typeValueMulti"]) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Group" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Status" { $RequestBody.Add("type", $objectTypeID) $RequestBody.Add("typeValueMulti", $PSBoundParameters["typeValueMulti"]) } } #Add required attributes to the hash for all Object Type "Default" switch ($PSBoundParameters["DefaultType"]) { { @("Text", "Integer", "Boolean", "Double", "Date", "Date_Time", "Email", "TextArea", "IP_Address") -contains $_ } { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) } "URL" { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) $RequestBody.Add("additionalValue", $PSBoundParameters["additionalValue"]) } "Select" { $RequestBody.Add("type", 0) $RequestBody.Add("defaultTypeId", $DefaultTypeID) $RequestBody.Add("options", $PSBoundParameters["options"]) } } # Add all the aditional Attributes. if ($uniqueAttribute) { $RequestBody.Add("uniqueAttribute", $UniqueAttribute) } if ($PSBoundParameters["minimumCardinality"]) { $RequestBody.Add("minimumCardinality", $PSBoundParameters["minimumCardinality"]) } if ($PSBoundParameters["maximumCardinality"]) { $RequestBody.Add("maximumCardinality", $PSBoundParameters["maximumCardinality"]) } if ($PSBoundParameters["suffix"]) { $RequestBody.Add("suffix", $PSBoundParameters["suffix"]) } if ($PSBoundParameters["includeChildObjectTypes"]) { $RequestBody.Add("includeChildObjectTypes", $PSBoundParameters["includeChildObjectTypes"]) } if ($PSBoundParameters["iql"]) { $RequestBody.Add("iql", $PSBoundParameters["iql"]) } if ($PSBoundParameters["summable"]) { $RequestBody.Add("summable", $PSBoundParameters["summable"]) } if ($PSBoundParameters["regexValidation"]) { $RequestBody.Add("regexValidation", $PSBoundParameters["regexValidation"]) } if ($PSBoundParameters["options"]) { $RequestBody.Add("options", $PSBoundParameters["options"]) } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method PUT } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Get-InsightObjectTypes { <# .SYNOPSIS Resource to find object types in Insight for a specific object schema. The object types are responded in a flat list. .DESCRIPTION Resource to find object types in Insight for a specific object schema. The object types are responded in a flat list. .PARAMETER ID The object type ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : My Object Type type : 0 description : A Sample Object Type icon : @{id=1; name=3D Printer; url16=/rest/insight/1.0/objecttype/1/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2 lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29t LnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTAxMiwiZXhwIjoxNjAwMjMxMTkyLCJpYXQiOjE2MDAyMzEwMTJ9.oHQ6uHuginJCihoHT2YdSqPMBzgWD KpwZmVoBtlPqY0; url48=/rest/insight/1.0/objecttype/1/icon.png?size=48&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnN pZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhb GFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTAxMiwiZXhwIjoxNjAwMjMxMTkyLCJpYXQiOjE2MDAyMzEwMTJ9.oHQ6uHuginJCihoHT2YdSqPMBzgWDKpwZmVoBt lPqY0} position : 0 created : 2020-09-16T04:36:52.885Z updated : 2020-09-16T04:36:52.885Z objectCount : 0 objectSchemaId : 3 inherited : False abstractObjectType : False parentObjectTypeInherited : False .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+types .EXAMPLE Get-InsightObjectTypes -ID 3 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objectschema/$($ID)/objecttypes/flat" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function New-InsightObjectTypes { <# .SYNOPSIS Resource to create an object type in Insight. .DESCRIPTION Resource to create an object type in Insight. .PARAMETER Name The object type name. .PARAMETER Description The object type description. .PARAMETER IconID The object type icon ID. .PARAMETER ParentObjectTypeID The parent object type id that new object will be placed in .PARAMETER objectSchemaId The object schema id .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : My Object Type type : 0 description : A Sample Object Type icon : @{id=1; name=3D Printer; url16=/rest/insight/1.0/objecttype/1/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2 lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29t LnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTAxMiwiZXhwIjoxNjAwMjMxMTkyLCJpYXQiOjE2MDAyMzEwMTJ9.oHQ6uHuginJCihoHT2YdSqPMBzgWD KpwZmVoBtlPqY0; url48=/rest/insight/1.0/objecttype/1/icon.png?size=48&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnN pZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhb GFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTAxMiwiZXhwIjoxNjAwMjMxMTkyLCJpYXQiOjE2MDAyMzEwMTJ9.oHQ6uHuginJCihoHT2YdSqPMBzgWDKpwZmVoBt lPqY0} position : 0 created : 2020-09-16T04:36:52.885Z updated : 2020-09-16T04:36:52.885Z objectCount : 0 objectSchemaId : 3 inherited : False abstractObjectType : False parentObjectTypeInherited : False .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+types .EXAMPLE New-InsightObjectTypes -Name "My Object Type" -Description "A Sample Object Type" -IconID 1 -objectSchemaId 3 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$IconID, [Parameter(Mandatory = $false)] [int]$parentObjectTypeId, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$objectSchemaId, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttype/create" $RequestBody = @{ 'name' = $Name 'iconId' = $iconId 'objectSchemaId' = $objectSchemaId } If ($Description) { $RequestBody.Add('description', $Description) } If ($parentObjectTypeId) { $RequestBody.Add('description', $parentObjectTypeId) } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method POST } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Remove-InsightObjectTypes { <# .SYNOPSIS Resource to delete an object type in Insight. .DESCRIPTION Resource to delete an object type in Insight. .PARAMETER ID The Object Type ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : My Object Type type : 0 description : A Sample Object Type icon : @{id=1; name=3D Printer; url16=/rest/insight/1.0/objecttype/1/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2 lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29t LnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDI0MDIwNiwiZXhwIjoxNjAwMjQwMzg2LCJpYXQiOjE2MDAyNDAyMDZ9.fOtVat8TB9dOkl-8EWw4z1ztqCBtD LFNeKXi6PjFcW0; url48=/rest/insight/1.0/objecttype/1/icon.png?size=48&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnN pZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhb GFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDI0MDIwNiwiZXhwIjoxNjAwMjQwMzg2LCJpYXQiOjE2MDAyNDAyMDZ9.fOtVat8TB9dOkl-8EWw4z1ztqCBtDLFNeKXi6P jFcW0} position : 0 created : 2020-09-16T04:36:52.885Z updated : 2020-09-16T04:50:45.458Z objectCount : 0 objectSchemaId : 3 inherited : False abstractObjectType : False parentObjectTypeInherited : False .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+types .EXAMPLE Remove-InsightObjectTypes -id 1 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttype/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method DELETE } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Set-InsightObjectTypes { <# .SYNOPSIS Resource to create an object type in Insight. .DESCRIPTION Resource to create an object type in Insight. .PARAMETER ID The object type ID. .PARAMETER Name The status Name. .PARAMETER Description The object type Description. .PARAMETER IconID The object type IconID (Can be collected via Get-InsightIcons). .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 1 name : My Object Type type : 0 description : A Sample Object Type - Updated icon : @{id=1; name=3D Printer; url16=/rest/insight/1.0/objecttype/1/icon.png?size=16&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2 lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29t LnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTg0NSwiZXhwIjoxNjAwMjMyMDI1LCJpYXQiOjE2MDAyMzE4NDV9.kOqWqYE7nswEI7WZql7i3pOPp2MM8 frWlgwx9fB5GNI; url48=/rest/insight/1.0/objecttype/1/icon.png?size=48&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnN pZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhb GFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDIzMTg0NSwiZXhwIjoxNjAwMjMyMDI1LCJpYXQiOjE2MDAyMzE4NDV9.kOqWqYE7nswEI7WZql7i3pOPp2MM8frWlgwx9f B5GNI} position : 0 created : 2020-09-16T04:36:52.885Z updated : 2020-09-16T04:50:45.458Z objectCount : 0 objectSchemaId : 3 inherited : False abstractObjectType : False parentObjectTypeInherited : False .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+types .EXAMPLE Set-InsightObjectTypes -ID 1 -Name "My Object Type" -Description "A Sample Object Type - Updated" -IconID 1 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $True)] [int]$ID, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$IconID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/objecttype/$($ID)" $RequestBody = @{ 'name' = $Name 'iconId' = $iconId } If ($Description) { $RequestBody.Add('description', $Description) } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method PUT } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Get-InsightObject { <# .SYNOPSIS Resource to load an object in Insight. .DESCRIPTION Resource to load an object in Insight. .PARAMETER ID The objects ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 3 label : MyObject objectKey : ABC-3 avatar : @{url16=/rest/insight/1.0/objecttype/2/icon.png?size=16&uuid=3269b6c6-10cc-41de-88ba-99efae71f8...IjoxNjAwMzA3MDc4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-QvW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; objectId=3} objectType : @{id=2; name=My Object Type; type=0; description=A Sample Object Type; icon=; position=0; created=2020-09-16T07:14:02.118Z; updated=2020-09-16T07:14:02.118Z; objectCount=0; objectSchemaId=3; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False} created : 2020-09-17T01:11:02.596Z updated : 2020-09-17T01:11:02.596Z hasAvatar : False timestamp : 1600305062596 attributes : {@{id=9; objectTypeAttribute=; objectTypeAttributeId=7; objectAttributeValues=System.Object[]; objectId=3}, @{id=12; objectTypeAttribute=; objectTypeAttributeId=8; objectAttributeValues=System.Object[]; objectId=3}, @{id=10; objectTypeAttribute=; objectTypeAttributeId=9; objectAttributeValues=System.Object[]; objectId=3}, @{id=11; objectTypeAttribute=; objectTypeAttributeId=10; objectAttributeValues=System.Object[]; objectId=3}...} extendedInfo : @{openIssuesExists=False; attachmentsExists=False} _links : @{self=/secure/ShowObject.jspa?id=3} name : MyObject .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Objects .EXAMPLE Get-InsightObject -ID "3" -InsightApiKey $InsightApiKey Get-InsightObject -ID "ABC-3" -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [String]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/object/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function New-InsightObject { <# .SYNOPSIS Resource to create object in Insight. .DESCRIPTION Resource to create object in Insight. .PARAMETER objectTypeId The Object Type ID .PARAMETER attributes An Array of parameters built via 'New-InsightObjectAttribute' .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 5 label : Test name objectKey : ABC-5 avatar : @{url16=/rest/insight/1.0/objecttype/2/icon.png?size=16&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOi JIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6d HJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdod CIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDMxNDk2MywiZXhwIjoxNjAwMzE1MTQzLCJpYXQiOjE2MDAzMTQ5NjN9.vzQiy3zF1cgjWFBeymAv1Q6lU0dk-Ewv6kuE 7Gh0ins; url48=/rest/insight/1.0/objecttype/2/icon.png?size=48&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJ hbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaW dodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiw...; objectId=5} objectType : @{id=2; name=My Object Type; type=0; description=A Sample Object Type; icon=; position=0; created=2020-09-16T07:14:02.118Z; updated=2020-09-16T07:14:02.118Z; objectCount=0; objectSchemaId=3; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False} created : 2020-09-17T03:56:04.262Z updated : 2020-09-17T03:56:04.262Z hasAvatar : False timestamp : 1600314964262 _links : @{self=/secure/ShowObject.jspa?id=5} name : Test name .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Objects .EXAMPLE New-InsightObject -objectTypeId 2 -attributes $array -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$objectTypeId, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true,valuefrompipelinebypropertyname = $true)] [array]$attributes, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/object/create" $RequestBody = @{ 'objectTypeId' = $objectTypeId 'attributes' = @($attributes) } $RequestBody = ConvertTo-Json $RequestBody -Depth 20 $RequestBody } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method POST } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function New-InsightObjectAttribute { <# .SYNOPSIS Resource to create an attribute array to send to New-InsightObject. .DESCRIPTION Resource to create an attribute array to send to New-InsightObject. .PARAMETER objectTypeAttributeId The object type attribute ID to populate. .PARAMETER objectAttributeValues The object attribute value. .OUTPUTS Name Value ---- ----- objectTypeAttributeId 8 objectAttributeValues {System.Collections.Hashtable} .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+type+attributes .EXAMPLE $1 = New-InsightObjectAttribute -objectTypeAttributeId 8 -objectAttributeValues "Test name" $2 = New-InsightObjectAttribute -objectTypeAttributeId 12 -objectAttributeValues "test ID" $array = @($1,$2) # For use with New-InsightObject #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true,valuefrompipelinebypropertyname = $true)] [int]$objectTypeAttributeId, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true,valuefrompipelinebypropertyname = $true)] [String]$objectAttributeValues ) begin { } process { $Attribute = @{ 'objectTypeAttributeId' = $objectTypeAttributeId 'objectAttributeValues' = @(@{ 'value' = $objectAttributeValues }) } } end { Write-Output $Attribute } } function Remove-InsightObject { <# .SYNOPSIS Resource to delete an object in Insight. .DESCRIPTION Resource to delete an object in Insight. .PARAMETER ID The object ID. Takes a string of the ID or objectKey .PARAMETER InsightApiKey The Api key. .OUTPUTS id : 3 label : MyObject objectKey : ABC-3 avatar : @{url16=/rest/insight/1.0/objecttype/2/icon.png?size=16&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiw iaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDMwNjg5OCwiZXhwIjoxNjAwMzA3MDc4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-Q vW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; url48=/rest/insight/1.0/objecttype/2/icon.png?size=48&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoi NWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDMwNjg5OCwiZXhwIjoxNjAwMzA3MD c4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-QvW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; url72=/rest/insight/1.0/objecttype/2/icon.png?size=72&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppc mEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI 6MTYwMDMwNjg5OCwiZXhwIjoxNjAwMzA3MDc4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-QvW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; url144=/rest/insight/1.0/objecttype/2/icon.png?size=144&uuid=3269b6c6-10cc-41de-88ba-99efae71f889&jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1N iJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW 5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDMwNjg5OCwiZXhwIjoxNjAwMzA3MDc4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-QvW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; url288=/rest/insight/1.0/objecttype/2/icon.png?size=288&uuid=3269b6c6-10cc-41de-88ba-99efae71f889& jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjb20ucmlhZGFsYWJzLmppcmEucGx1Z2lucy5pbnNpZ2h0Iiwic3ViIjoiNWVkZjBhNDNlMzFmNjIwYWJhNjYyZjAyIiwiaW5zaWdodCI6dHJ1ZSwiY2xpZW50S2V5IjoiN2VmZmExZGQtYzNiMS0zMjQ4LWFjZDUtNjdjNDcxZWFkOGQzIiwiaXNzIjoiY 29tLnJpYWRhbGFicy5qaXJhLnBsdWdpbnMuaW5zaWdodCIsIm9yaWdpbmFsbHlJc3N1ZWRBdCI6MTYwMDMwNjg5OCwiZXhwIjoxNjAwMzA3MDc4LCJpYXQiOjE2MDAzMDY4OTh9._CaSkX-QvW1BlK7-4XJB9UikOvegJS-YSjCrCtYUl7A; objectId=3} objectType : @{id=2; name=My Object Type; type=0; description=A Sample Object Type; icon=; position=0; created=2020-09-16T07:14:02.118Z; updated=2020-09-16T07:14:02.118Z; objectCount=0; objectSchemaId=3; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False} created : 2020-09-17T01:11:02.596Z updated : 2020-09-17T01:11:02.596Z hasAvatar : False timestamp : 1600305062596 attributes : {@{id=9; objectTypeAttribute=; objectTypeAttributeId=7; objectAttributeValues=System.Object[]; objectId=3}, @{id=12; objectTypeAttribute=; objectTypeAttributeId=8; objectAttributeValues=System.Object[]; objectId=3}, @{id=10; objectTypeAttribute=; objectTypeAttributeId=9; objectAttributeValues=System.Object[]; objectId=3}, @{id=11; objectTypeAttribute=; objectTypeAttributeId=10; objectAttributeValues=System.Object[]; objectId=3}...} extendedInfo : @{openIssuesExists=False; attachmentsExists=False} _links : @{self=/secure/ShowObject.jspa?id=3} name : MyObject .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Objects .EXAMPLE Remove-InsightObject -ID "3" -InsightApiKey $InsightApiKey Remove-InsightObject -ID "ABC-3" -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/object/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method DELETE } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function Set-InsightObject { <# .SYNOPSIS Resource to update an object in Insight. .DESCRIPTION Resource to update an object in Insight. .PARAMETER ID The ID .PARAMETER Attributes An array of attributes. colelcted from New-InsightObjectAttributes .PARAMETER InsightApiKey The Api key. .OUTPUTS .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Object+schema .EXAMPLE #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [int]$ID, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [array]$Attributes, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.iorest/insight/1.0/object/$($ID)" $RequestBody = @{ 'objectTypeId' = $objectTypeId 'attributes' = @($attributes) } $RequestBody = ConvertTo-Json $RequestBody -Depth 20 $RequestBody } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method PUT } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } Write-Output $response } } function Get-InsightObjectTypes { <# .SYNOPSIS Resource to load a status in Insight. .DESCRIPTION Resource to load a status in Insight. .PARAMETER InsightApiKey The Api key. .OUTPUTS id name description category -- ---- ----------- -------- 1 Action Needed 2 2 Active 1 3 Closed 0 4 In Service 2 5 Running 1 6 Stopped 0 7 Support Requested 2 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Statuses .EXAMPLE Get-InsightObjectTypes -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/config/statustype" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method GET } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function New-InsightStatuses { <# .SYNOPSIS Resource to create a status in Insight. .DESCRIPTION Resource to create a status in Insight. .PARAMETER Name The Status Name. .PARAMETER Description The Status Description. .PARAMETER Category The status Category. .PARAMETER InsightApiKey The Api Secret. .OUTPUTS id name description category -- ---- ----------- -------- 8 My New Status Sample Status 1 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Statuses .EXAMPLE New-InsightStatuses -Name "My New Status" -Description "Sample Status" -category Active -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Description, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [Validateset("Inactive","Active","Pending")] [String]$category, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey switch ($category) { "Inactive" { $CategoryID = 0 } "Active" { $CategoryID = 1 } "Pending" { $CategoryID = 2 } } } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/config/statustype" $RequestBody = @{ 'name' = $Name 'description' = $Description 'category' = $CategoryID } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method POST } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Remove-InsightObjectTypes { <# .SYNOPSIS Resource to delete a status in Insight. .DESCRIPTION Resource to delete a status in Insight. .PARAMETER ID The status ID. .PARAMETER InsightApiKey The Api key. .OUTPUTS No output from API .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Statuses .EXAMPLE Remove-InsightObjectTypes -ID 8 -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ID, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/config/statustype/$($ID)" } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Method DELETE } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } function Set-InsightStatuses { <# .SYNOPSIS Resource to update a status in Insight. .DESCRIPTION Resource to update a status in Insight. .PARAMETER ID The status ID. .PARAMETER Name The status name. .PARAMETER Description The status description .PARAMETER Category The status category. .PARAMETER InsightApiKey The Api key. .OUTPUTS id name description category -- ---- ----------- -------- 8 My New Status Sample Status - Updated 1 .LINK https://documentation.mindville.com/display/INSCLOUD/REST+API+-+Statuses .EXAMPLE Set-InsightStatuses -ID 8 -Name "My New Status" -Description "Sample Status - Updated" -category Active -InsightApiKey $InsightApiKey #> [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$ID, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Name, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [string]$Description, [ValidateNotNullOrEmpty()] [Parameter(Mandatory = $true)] [Validateset("Inactive","Active","Pending")] [String]$Category, [ValidateNotNullOrEmpty()] [Alias('ApiKey')] [string]$InsightApiKey ) begin { #Generate Headers $headers = New-InsightHeaders -InsightApiKey $InsightApiKey switch ($category) { "Inactive" { $CategoryID = 0 } "Active" { $CategoryID = 1 } "Pending" { $CategoryID = 2 } } } process { $Request = [System.UriBuilder]"https://insight-api.riada.io/rest/insight/1.0/config/statustype/$($ID)" $RequestBody = @{ 'name' = $Name 'description' = $Description 'category' = $CategoryID } $RequestBody = ConvertTo-Json $RequestBody -Depth 1 } end { try { $response = Invoke-RestMethod -Uri $Request.Uri -Headers $headers -Body $RequestBody -Method PUT } catch { Write-Error -Message "$($_.Exception.Message)" -ErrorId $_.Exception.Code -Category InvalidOperation } $response } } |