public/Apply-SkylineSchemas.ps1

Function Apply-SkylineSchemas {
    <#
    .SYNOPSIS
    Find all .xml files in a directory and applies them to a site
     
    .DESCRIPTION
    Find all .xml files in a directory and applies them to a site
     
    Reference: https://github.com/SharePoint/PnP-Provisioning-Schema
 
    .EXAMPLE
    Save-SkylineListProvisioningSchema -Directory "C:\Schemas"
 
    .PARAMETER Directory
    Local directory where the XML files are located
 
    .PARAMETER Web
    The web to apply the command to. Omit this parameter to use the current web.
     
    #>


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

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

        Try
        {     
            $PSBoundParameters.Remove("Directory") | Out-Null

            $XMLSchemas = Get-ChildItem -Path "$($Directory)\*.xml"
            $PNPSchemas = Get-ChildItem -Path "$($Directory)\*.pnp"

            @($XMLSchemas + $PNPSchemas) | ForEach-Object {
                Apply-PnPProvisioningTemplate -Path $_.FullName @PSBoundParameters
            }    

        }
        Catch
        {
            Throw $_
        }
    }
}