Provision images in a communication site's style library with PowerShell

Provision images in a communication site's style library with PowerShell

To programmatically provision an image to the Style Library folder of a SharePoint Online modern communication site the trick is that you must first enable customizations on the site collection or else you will get an “Access Denied” error.

Import-Module "Microsoft.Online.SharePoint.PowerShell"
Connect-SPOService -Url "https://contoso-admin.sharepoint.com" -Credential $Credentials
Set-SpoSite -Identity "https://contoso.sharepoint.com/sites/thesite" -DenyAddAndCustomizePages $false

Then use PnP PowerShell to upload the file:

Import-Module SharePointPnPPowerShellOnline
$assetsFolderPath = "Style Library/myfolder"
Add-PnPFile -Folder $assetsFolderPath -Path ".\myimage.png"

Comments