Functions/Copy-IAWidget.ps1
Function Copy-IAWidget{ Param( [Parameter(Mandatory = $true, ParameterSetName='IAWidget')] [PSobject]$IAWidget, [Switch]$Passthru ) # Create empty widget object $IAWidgetObject = New-Object -TypeName PSObject # Creating a Task Schedule Write-Verbose "Creating a Task Schedule." | Out-Null $IATaskSchedule = Get-IATaskSchedule -Id $IAWidget.DataDefinition.TaskScheduleId if($IATaskSchedule){ $IATaskSchedule = $IATaskSchedule | Select-Object -Property Enabled, Type, Interval $IATaskSchedule = New-IATaskSchedule -IATaskSchedule $IATaskSchedule -Passthru } else{ Throw "IATaskSchedule missing!" } # Creating a new configuration ### How to pass an array of strings into the remove parameter? $IAWidget.Configuration.PSObject.Properties.Remove('Id') $IAWidget.Configuration.PSObject.Properties.Remove('CreatedBy') $IAWidget.Configuration.PSObject.Properties.Remove('CreatedDate') $IAWidget.Configuration.PSObject.Properties.Remove('LastUpdatedBy') $IAWidget.Configuration.PSObject.Properties.Remove('LastUpdated') $IAWidget.Configuration.PSObject.Properties.Remove('@odata.context') $IAConfiguration = New-IAConfiguration -IAConfigurationDataModel $IAWidget.Configuration -Name "$($IAWidget.ConnectorModuleType.Name)Configuration" -Passthru $IAConfigurationId = $IAConfiguration.Id $IAWidgetConfiguration = $null $IAWidgetConfiguration = $IAConfiguration $IAWidgetConfiguration.PSObject.Properties.Remove('@odata.context') $IAWidgetConfiguration.PSObject.Properties.Remove('CreatedDate') $IAWidgetConfiguration.PSObject.Properties.Remove('Id') $IAWidgetConfiguration.PSObject.Properties.Remove('CreatedBy') $IAWidgetConfiguration.PSObject.Properties.Remove('LastUpdated') $IAWidgetConfiguration.PSObject.Properties.Remove('LastUpdatedBy') $IAWidgetConfiguration | Add-Member -MemberType NoteProperty -Name '@odata.type' -Value "#IA_Backend.Entities.DataDefinitions.ConfigMgr.$($IAWidget.ConnectorModuleType.Name)Configuration" -Force # Creating a DataDefinition for the Widget Write-Output "Creating the DataDefinition" | Out-Null $IADataDefinitionObject = New-IADataDefinitionObject -IAWidgetConfiguration $IAWidgetConfiguration -IATaskScheduleId $IATaskSchedule.Id -IAConnectorModuleId $IAWidget.DataDefinition.ConnectorModuleId $IADataDefinition = New-IADataDefinition -IADataDefinitionObject $IADataDefinitionObject -PassThru # Set the correct ConfigurationId $IADataDefinition.ConfigurationId = $IAConfigurationId Set-IADataDefinition -IADataDefinition $IADataDefinition # Set the WidgetType object switch($IAWidget.WidgetType.Name){ {$_ -in 'Bar', 'Pie', 'List', 'Custom Query List'} { $IAWidgetConfigurationDonutObject = New-IAWidgetConfigurationDonutObject $IAWidgetConfigurationObject = New-IAWidgetConfigurationDonut -IAWidgetConfigurationDonutObject $IAWidgetConfigurationDonutObject -Passthru } {$_ -eq 'Donut'}{ $DonutDataValueFieldMaps = Get-IAWidgetDataValueFieldMaps -WidgetTemplateId $IAWidget.WidgetTemplateId | Select-Object -ExpandProperty WidgetDataValueFieldMaps $IAWidgetCenterLabelDataField = $DonutDataValueFieldMaps | Where-Object -Property Default -eq $true | Select-Object -First 1 if($IAWidgetCenterLabelDataField.Count -eq 0){ $IAWidgetCenterLabelDataField = $DonutDataValueFieldMaps | Select-Object -First 1 } $IAWidgetConfigurationDonutObject = New-IAWidgetConfigurationDonutObject -CenterLabelDataFieldName $IAWidgetCenterLabelDataField.DataValueFieldName -ShowCenterSubTitle $true -ShowCenterPercentage $true $IAWidgetConfigurationObject = New-IAWidgetConfigurationDonut -IAWidgetConfigurationDonutObject $IAWidgetConfigurationDonutObject -Passthru } {$_ -eq 'Text'}{ $RawContent = New-IARawContent -IAWidgetTemplate $IAWidget.WidgetTemplate $IAWidgetConfigurationTextObject = New-IAWidgetConfigurationTextObject -RawContent $RawContent $IAWidgetConfigurationObject = New-IAWidgetConfigurationText -IAWidgetConfigurationTextObject $IAWidgetConfigurationTextObject -Passthru } {$_ -eq "History"} { $IAWidgetConfigurationHistoriesObject = New-IAWidgetConfigurationHistoriesObject -ChartType "line" ` -PeriodType "Entire Period" ` -PeriodSlidingType "Rolling" ` -PeriodValue 1 ` -HistoryUnit "Month(s)" ` -PeriodFixedStartDateTime "2009-12-31T22:00:00.000Z" ` -PeriodFixedEndDateTime "2098-12-31T22:00:00.000Z" $IAWidgetConfigurationObject = New-IAWidgetConfigurationHistories -IAWidgetConfigurationHistories $IAWidgetConfigurationHistoriesObject -Passthru } } $ColumnIndex = Get-IAWidget -All | Where-Object -Property GroupId -eq $IAWidget.GroupId | Select-Object -ExpandProperty ColumnIndex | Sort-Object -Descending | Select-Object -First 1 $ColumnIndex += 1 $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'Title' -Value $IAWidget.Title -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'ConnectorModuleTypeId' -Value $IAWidget.ConnectorModuleTypeId -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'Enabled' -Value $IAWidget.Enabled -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'WidgetTemplateId' -Value $IAWidget.WidgetTemplateId -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'GroupId' -Value $IAWidget.GroupId -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'WidgetTypeId' -Value $IAWidget.WidgetType.Id -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'DataDefinitionId' -Value $IADataDefinition.Id -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'WidgetConfigurationBaseId' -Value $IAWidgetConfigurationObject.Id -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'SubTitle' -Value $IAWidget.SubTitle -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'HyperlinkUri' -Value $IAWidget.HyperlinkUri -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'RowIndex' -Value $IAWidget.RowIndex -Force $IAWidgetObject | Add-Member -MemberType NoteProperty -Name 'ColumnIndex' -Value $ColumnIndex -Force $NewIAWidget = New-IAWidget -IAWidgetObject $IAWidgetObject -PassThru # Create WidgetDataValueFieldMaps $IAWidgetDataValueFieldMaps = Get-IAWidgetDataValueFieldMaps -WidgetTemplateId $NewIAWidget.WidgetTemplateId | Select-Object -ExpandProperty WidgetDataValueFieldMaps foreach($wdvfm in $IAWidgetDataValueFieldMaps){ $wdvfm.WidgetId = $NewIAWidget.Id $wdvfm.PSObject.Properties.Remove('WidgetTemplateId') $wdvfm.PSObject.Properties.Remove('Id') New-IAWidgetDataValueFieldMaps -IAWidgetDataValueFieldMaps $wdvfm } if($Passthru){ return $NewIAWidget } } |