Skip to content

Instantly share code, notes, and snippets.

@ypcode
Created May 16, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/fbdf3445f4fcf7f7398c48ba70c1493a to your computer and use it in GitHub Desktop.
Save ypcode/fbdf3445f4fcf7f7398c48ba70c1493a to your computer and use it in GitHub Desktop.
$site = "https://contoso.sharepoint.com/sites/site1"
$pageName = "AModernPage.aspx"
$webPartId = "af660fc1-c09b-4c15-b093-2b74b047286b"
$choice1 = "Choice 1"
$choice2 = "Choice 2"
# Put all the WebPart properties in a PowerShell hashtable
$webPartProps = @{
myChoices = @($choice1, $choice2);
description = 'My "Awesome" WebPart';
};
# Build JSON string from PowerShell hashtable object
$webPartPropsJson = $webPartProps | ConvertTo-Json -Compress
# Make sure to add the backticks, double the JSON double-quotes and escape double quotes in properties'values
$webPartPropsJson = '`"{0}"`' -f $webPartPropsJson.Replace('\','\\').Replace('"', '""')
o365 spo page clientsidewebpart add -u $site -n $pageName --webPartId $webPartId --webPartProperties $webPartPropsJson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment