Skip to content

Instantly share code, notes, and snippets.

@rjesh-git
Last active March 8, 2018 05:04
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 rjesh-git/f4b768882a801c67b3292b62c31a9732 to your computer and use it in GitHub Desktop.
Save rjesh-git/f4b768882a801c67b3292b62c31a9732 to your computer and use it in GitHub Desktop.
Add Client Side WebPart using PnP PoSh
function ConvertTo-Hashtable {
[CmdletBinding()]
[OutputType('hashtable')]
param (
[Parameter(ValueFromPipeline)]
$InputObject
)
process {
if ($null -eq $InputObject) {
return $null
}
if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) {
$collection = @(
foreach ($object in $InputObject) {
ConvertTo-Hashtable -InputObject $object
}
)
Write-Output -NoEnumerate $collection
} elseif ($InputObject -is [psobject]) {
$hash = @{}
foreach ($property in $InputObject.PSObject.Properties) {
$hash[$property.Name] = ConvertTo-Hashtable -InputObject $property.Value
}
$hash
} else {
$InputObject
}
}
}
Connect-PnPOnline -Url https://m365x642699.sharepoint.com/sites/NewYork03
$jsonObj = '{"title":"Site Contact","layout":2,"persons":[{"id":"i:0#.f|membership|alexw@m365x642699.onmicrosoft.com"}]}'
$wp = $jsonObj | ConvertFrom-Json | ConvertTo-HashTable
#Add People webpart with default user, to column 2 in section 1
Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType People -Section 1 -Column 2 -WebPartProperties $wp
#Finally publish the page
Set-PnPClientSidePage -Identity "Home" -Publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment