Skip to content

Instantly share code, notes, and snippets.

@rjesh-git
Last active March 8, 2018 05:04

Revisions

  1. rjesh-git revised this gist Mar 8, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion addClientSideWebPart.ps1
    Original file line number Diff line number Diff line change
    @@ -35,4 +35,8 @@ 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-PnPClientSideWebPart -Page "Home" -DefaultWebPartType People -Section 1 -Column 2 -WebPartProperties $wp
    #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
  2. rjesh-git revised this gist Mar 8, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion addClientSideWebPart.ps1
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,6 @@ function ConvertTo-Hashtable {
    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-PnPClientSideWebPart -Page "Home" -DefaultWebPartType People -Section 1 -Column 2 -WebPartProperties $wp
  3. rjesh-git created this gist Mar 8, 2018.
    39 changes: 39 additions & 0 deletions addClientSideWebPart.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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-PnPClientSideWebPart -Page "Home" -DefaultWebPartType People -Section 1 -Column 2 -WebPartProperties $wp