Functions/Get-IAConfiguration.ps1
Function Get-IAConfiguration { <# .SYNOPSIS Returns a configuration that is used to set up a Widget .DESCRIPTION Each Widget requires a Configuration when created. This function can be used to get the Configuration, that is used when creating a Widget. .OUTPUTS An IA Configuration as a PSObject .EXAMPLE Get-IAConfiguration -Interactive .EXAMPLE Get-IAConfiguration -All .EXAMPLE Get-IAConfiguration -ConfigurationName Collections .EXAMPLE Get-IAConfiguration -ConfigurationName Collections -ConfigurationId 'ab273c53-1444-469d-6837-08d76e94133f' #> [CmdletBinding(DefaultParameterSetName='ConfigurationId')] Param( [Parameter(ParameterSetName='ConfigurationId')] [Guid] $Id, [Parameter(ParameterSetName='All')] [Switch]$All, [Parameter(Mandatory = $true, ParameterSetName='Interactive')] [Switch]$Interactive ) DynamicParam { $Bucket = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary $AttributeList = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute] $Values = (Invoke-IAQuery -QueryUrl "configmgr/" -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 = 'ConfigurationId' $AttribParameter.Position = 0 $AttributeList.Add($AttribParameter) $ParameterName = 'Name' $Parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($ParameterName,[String], $AttributeList) $Bucket.Add($ParameterName, $Parameter) $Bucket } End { Foreach ($key in $PSBoundParameters.Keys) { if ($MyInvocation.MyCommand.Parameters.$key.isDynamic) { Set-Variable -Name $key -Value $PSBoundParameters.$key } } if($Interactive){ [XML]$XML = Invoke-IAQuery -QueryUrl 'configmgr/$metadata' -Method Get $XMLBase = $XML.edmx.DataServices.schema $ConfigurationDataModels = $XMLBase | Where-Object -Property Namespace -EQ IA_Backend.Entities.DataDefinitions.ConfigMgr | Select-Object -ExpandProperty EntityType $Name = $ConfigurationDataModels | Select-Object -ExpandProperty Name | Out-GridView -PassThru $Name = $Name + "s" } $Uri = "configmgr/$Name" if($All){} elseif($Name -and $Id){ $Uri += "($Id)" } $response = Invoke-IAQuery -QueryUrl $Uri -Method Get if($Interactive -or $All -or ($Name -and !$Id)) { return $response.value } else{ return $response } } } |