public/Save-SkylineListSchema.ps1

Function Save-SkylineListSchema {
    <#
    .SYNOPSIS
    Extracts the PnP Provisioning Schema XML for the specific list(s)
     
    .DESCRIPTION
    Extracts the PnP Provisioning Schema XML for the specific list(s)
     
    Reference: https://github.com/SharePoint/PnP-Provisioning-Schema
 
    .EXAMPLE
    Save-SkylineListProvisioningSchema -List "Documents" -Path "C:\Schemas\Documents.xml"
 
    .PARAMETER List
    Title of the target list. May pass multiple lists as -List "List1", "List2"
 
    .PARAMETER Path
    Path to export the schema to. Example: C:\Schemas\Documents.xml
 
    .PARAMETER Web
    The web to apply the command to. Omit this parameter to use the current web.
    #>


    [cmdletbinding()]
    param(
        [parameter(Mandatory = $True)]
        [string[]]$List, 
        [parameter(Mandatory = $True)]
        [string]$Path,
        [Microsoft.SharePoint.Client.Web]$Web
    )

    Process
    {
        Write-Debug ( "Running $($MyInvocation.MyCommand).`n" + "PSBoundParameters:`n$($PSBoundParameters | Format-List | Out-String)")

        Try
        {     
            $PSBoundParameters.Remove("List") | Out-Null
            $PSBoundParameters.Remove("Path") | Out-Null
            $PSBoundParameters.Remove("IncludeContentTypesAndColumns") | Out-Null

            $Directory = Ensure-SkylineDirectory $Path
            $FileName = Get-SkylineFileName $Path
            $Path = "$Directory\$FileName"
            $TemporaryPath = "$Directory\$FileName.temp.xml"

            #Setup our pnp extraction handlers
            $Handlers = @("Lists")

            #Invoke PnP to extract the specified lists from the connected SharePoint site as a provisioning schema XML file
            Get-PnPProvisioningTemplate -Handlers $Handlers -Out $TemporaryPath -Force @PSBoundParameters

            #Filter schema XML for specified lists and optionally the site content types and columns
            [XML]$SchemaXml = Get-SkylineListSchemaXml -SchemaXmlPath $TemporaryPath -List $List

            #Save the filtered schema XML to the specified path
            $SchemaXml.Save($Path)

            #Remove temporary full schema XML file
            Remove-Item -Path $TemporaryPath -Force
        }
        Catch
        {
            Throw $_
        }
    }
}