private/Get-SkylineListSchemaXml.ps1
Function Get-SkylineListSchemaXml { <# .SYNOPSIS Given a full schema XML object, this function will return the filtered schema XML containing only the specified list(s) and optional site content types and columns .DESCRIPTION Given a full schema XML object, this function will return the filtered schema XML containing only the specified list(s) and optional site content types and columns .PARAMETER List Title of the target list. May pass multiple lists as -List "List1", "List2" .PARAMETER SchemaXmlPath Provisioning schema XML path to filter down to the specified lists(s) #> [cmdletbinding()] param( [parameter(Mandatory = $True)] [string[]]$List, [parameter(Mandatory = $True)] [string]$SchemaXmlPath ) Process { Write-Debug ( "Running $($MyInvocation.MyCommand).`n" + "PSBoundParameters:`n$($PSBoundParameters | Format-List | Out-String)") Try { [XML]$SchemaXml = Get-Content -Path $SchemaXmlPath #Find XML nodes to remove which don't match the passed -List $ListNodesToRemove = @($SchemaXml.Provisioning.Templates.ProvisioningTemplate.Lists.ListInstance | Where-Object {!$List.Contains($_.Title)}) #Remove the XML nodes from the main XML document $ListNodesToRemove | ForEach-Object {$SchemaXml.Provisioning.Templates.ProvisioningTemplate.Lists.RemoveChild($_) | Out-Null} # if ($IncludeContentTypesAndColumns) # { # #Get content types of lists we want # $ListNodesToKeep = $SchemaXml.Provisioning.Templates.ProvisioningTemplate.Lists.ListInstance # $ContentTypeIdsToKeep = @($ListNodesToKeep | ForEach-Object {$_.ContentTypeBindings.ContentTypeBinding | ForEach-Object {$_.ContentTypeId}}); # #Trim down to only the content type we want # $ContentTypeNodesToRemove = @() # $ContentTypeNodesToKeep = @() # $SchemaXml.Provisioning.Templates.ProvisioningTemplate.ContentTypes.ContentType | ForEach-Object { # $ContentType = $_ # $Keeper = @($ContentTypeIdsToKeep | Where-Object {$_ -like "$($ContentType.ID)*"}) # if ($Keeper.Count -gt 0) { # $ContentTypeNodesToKeep += $ContentType # } else { # $ContentTypeNodesToRemove += $ContentType # } # } # $ContentTypeNodesToRemove | ForEach-Object {$SchemaXml.Provisioning.Templates.ProvisioningTemplate.ContentTypes.RemoveChild($_) | Out-Null} # #Get fields of the content type we want # $FieldNodesToKeep = @($ContentTypeNodesToKeep | ForEach-Object {$_.FieldRefs.FieldRef | ForEach-Object {$_.Name}}) # #Trim down site fields to only the ones referenced in the content type we want # $FieldNodesToRemove = @($SchemaXml.Provisioning.Templates.ProvisioningTemplate.SiteFields.Field | Where-Object {$FieldNodesToKeep -NotContains $_.Name}) # $FieldNodesToRemove | ForEach-Object {$SchemaXml.Provisioning.Templates.ProvisioningTemplate.SiteFields.RemoveChild($_) | Out-Null} # } return $SchemaXml } Catch { Throw $_ } } } |