public/Add-SkylineWebPart.ps1
Function Add-SkylineWebPart { <# .SYNOPSIS Uploads a webpart file to the Web Part Gallery .DESCRIPTION Uploads a webpart file to the Web Part Gallery .EXAMPLE Uploads a webpart file from local machine to Web Part Gallery Add-SkylineWebPart -Path "C:\Webparts\MyWebpart.dwp" -Group "Intranet" .PARAMETER Path Local path to the webpart xml file .PARAMETER Stream Stream with the file contents .PARAMETER FileName Name of the webpart file when using a stream, be sure to include .dwp or .webpart (e.g. mywebpart.dwp) .PARAMETER Group Group which the webpart should belong to. Default is 'Custom' .PARAMETER Web The web to apply the command to. Omit this parameter to use the current web. #> [cmdletbinding()] param( [parameter(Mandatory = $True, ParameterSetName='byPath')] [string]$Path = '', [parameter(Mandatory = $True, ParameterSetName='byStream')] $Stream = $null, [parameter(Mandatory = $True, ParameterSetName='byStream')] [string]$FileName = '', [parameter(Mandatory = $False)] [string]$Group = 'Custom', [Microsoft.SharePoint.Client.Web]$Web ) Process { Write-Debug ( "Running $($MyInvocation.MyCommand).`n" + "PSBoundParameters:`n$($PSBoundParameters | Format-List | Out-String)") Try { $PSBoundParameters.Remove("Group") | Out-Null Add-PnPFile -Folder "_catalogs/wp" -Checkout -Values @{ Group = $Group } @PSBoundParameters } Catch { Throw $_ } } } |