{"id":6277,"date":"2020-09-14T12:29:54","date_gmt":"2020-09-14T12:29:54","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6277"},"modified":"2020-09-14T12:29:54","modified_gmt":"2020-09-14T12:29:54","slug":"addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/","title":{"rendered":"Add,Update &#038; Delete Webpart of a SharePoint Page Using PNP PowerShell"},"content":{"rendered":"\n<p>In this blog, I have discussed about how to edit and delete a webpart of a\nSharePoint page using PNP PowerShell. Follow the below instructions to edit and\ndelete a webpart.<\/p>\n\n\n\n<p> \u2022 Add a webpart <br> \u2022 Edit webpart property<br> \u2022 Remove a webpart<br> \u2022 Run PowerShell script<\/p>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Add a webpart :<\/span><\/em><\/strong><\/p>\n\n\n\n<p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nFollow the below code to add a webpart to a wiki\npage.\n\n\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$siteUrl = Read-Host \"Enter site url  \" ;\n$url = Read-Host \"Enter page url like  'SitePages\/team-page.aspx' \" ;\ntry\n{\n    #Connect to sharepoint site\n\n    Connect-PNPOnline -Url $siteUrl -Credentials (Get-Credential)\n\n    #Add webpart to a Shareoint page\n\n     $WebXml =\"&lt;WebPart xmlns='http:\/\/schemas.microsoft.com\/WebPart\/v2' xmlns:iwp='http:\/\/schemas.microsoft.com\/WebPart\/v2\/ContentEditor'>\n        &lt;Title>Webpart Title&lt;\/Title>\n        &lt;FrameType>None&lt;\/FrameType>\n        &lt;Description>Allows authors to enter rich text content.&lt;\/Description>\n        &lt;IsIncluded>true&lt;\/IsIncluded>\n        &lt;ZoneID>QuickLinks&lt;\/ZoneID>\n        &lt;PartOrder>0&lt;\/PartOrder>\n        &lt;FrameState>Normal&lt;\/FrameState>\n        &lt;Height \/>\n        &lt;Width \/>\n        &lt;AllowRemove>true&lt;\/AllowRemove>\n        &lt;AllowZoneChange>true&lt;\/AllowZoneChange>\n        &lt;AllowMinimize>true&lt;\/AllowMinimize>\n        &lt;AllowConnect>true&lt;\/AllowConnect>\n        &lt;AllowEdit>true&lt;\/AllowEdit>\n        &lt;AllowHide>true&lt;\/AllowHide>\n        &lt;IsVisible>true&lt;\/IsVisible>\n        &lt;DetailLink \/>\n        &lt;HelpLink \/>\n        &lt;HelpMode>Modeless&lt;\/HelpMode>\n        &lt;Dir>Default&lt;\/Dir>\n        &lt;PartImageSmall \/>\n        &lt;MissingAssembly>Cannot import this Web Part.&lt;\/MissingAssembly>\n        &lt;PartImageLarge>\/_layouts\/15\/images\/mscontl.gif&lt;\/PartImageLarge>\n        &lt;IsIncludedFilter \/>\n        &lt;Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;\/Assembly>\n        &lt;TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart&lt;\/TypeName>\n        &lt;Content xmlns='http:\/\/schemas.microsoft.com\/WebPart\/v2\/ContentEditor'>&lt;div>Enter your Content here..........&lt;\/div>&lt;\/Content> \n        &lt;PartStorage xmlns='http:\/\/schemas.microsoft.com\/WebPart\/v2\/ContentEditor' \/>\n    &lt;\/WebPart>\"\n\n    Add-PNPWebPartToWikiPage -ServerRelativePageUrl $url -Xml $WebXml -Row 1 -Column 1 \n\n}\ncatch{}  <\/code><\/pre>\n\n\n\n<p>Also you can add the webpart by its path :<\/p>\n\n\n\n<p>      Add-PNPWebPartToWikiPage -ServerRelativePageUrl $url -Path &#8220;C:\\addwebpart.webpart&#8221; -Row 1 -Column 1 <\/p>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Edit Webpart Property :<\/span><\/em><\/strong><\/p>\n\n\n\n<p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nFollow the below code to edit an existing\nwebpart.\n\n\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$siteUrl = Read-Host \"Enter site url  \"\n$url = Read-Host \"Enter page url like  'SitePages\/team-page.aspx' \" ;\ntry\n{\n    #Connect to sharepoint site\n\n    Connect-PNPOnline -Url $siteUrl -Credentials (Get-Credential)\n\n    #Set property of a wikipage webpart\n\n    $webPart = Get-PNPWebPart -ServerRelativePageUrl $url\n    $webPartID = $webPart.Id\n\n    Set-PNPWebPartProperty -ServerRelativePageUrl $url -Identity $webPartID -Key Title -Value \"TodayList\"\n}\ncatch{}  \n\nYou can also set other properties of a webpart eg:-\n  Set-PNPWebPartProperty -ServerRelativePageUrl $url -Identity $webPartID -Key Height -Value 500 <\/code><\/pre>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Remove webpart :<\/span><\/em><\/strong><\/p>\n\n\n\n<p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nFor removing a webpart you have to follow below\ncodes.\n\n\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$siteUrl = Read-Host \"Enter site url  \"\n$url = Read-Host \"Enter page url like  'SitePages\/team-page.aspx' \" ;\ntry\n{\n    #Connect to sharepoint site\n\n    Connect-PNPOnline -Url $siteUrl -Credentials (Get-Credential)\n\n    $webPart = Get-PNPWebPart -ServerRelativePageUrl $url\n    $id = $webPart.Id\n\n    #Remove or delete a webpart\n\n    Remove-PNPWebPart -ServerRelativePageUrl $url -Identity $id\n  \n}\ncatch{} \n \nyou can also delete a webpart by its title\n Remove-PNPWebPart -ServerRelativePageUrl $url -Title \"mywebpart\" <\/code><\/pre>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Run the Script : <\/span><\/em><\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Right click on the PowerShell script which we have made.<\/li><li>Then click on &#8220;Run with PowerShell&#8221;.<\/li><li>Enter your SharePoint site Url in the script. Assign the value to $siteUrl.<\/li><li>Enter the page server relative Url like \u201c\/SitePages\/MyFirstPage.aspx\u201d.<\/li><li>Then give your SharePoint username and password.<\/li><\/ol>\n\n\n\n<p>Now you can check the output inside the created page. <\/p>\n\n\n\n<p><strong><em>Image-1:<\/em><\/strong><em> Created the Webpart<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/1.png\" alt=\"\" class=\"wp-image-6278\"\/><\/figure>\n\n\n\n<p><strong><em>Image-2:<\/em><\/strong><em> Changed the Title from \u201cteam list\u201d to \u201cTodayList\u201d<\/em><\/p>\n\n\n\n<p>Before running script,<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/2.png\" alt=\"\" class=\"wp-image-6279\" width=\"309\" height=\"244\"\/><\/figure>\n\n\n\n<p>After running script,<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/3.png\" alt=\"\" class=\"wp-image-6280\" width=\"451\" height=\"348\"\/><\/figure>\n\n\n\n<p><strong><em><span style=\"text-decoration: underline;\">Conclusion :<\/span><\/em><\/strong><\/p>\n\n\n\n<p>From the above code we can conclude that, the CRUD operation in\nSharePoint using PowerShell script is very effective as it reduces the amount\nof time needed to do the Operation. As we can see that the code size is less as\nwell so performance will be higher. So this will be the convenient method to do\nthe above operation.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong><em>Keywords : <\/em><\/strong><\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Wikipage&#8217;s webpart CRUD operation using PowerShell PNP.<\/li><li>Add,Update &amp; Delete webpart of a SharePoint page using PNP PowerShell.<\/li><li>Update webpart of wikipage using PNP PowerShell.<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, I have discussed about how to edit and delete a webpart of a SharePoint page using PNP PowerShell. Follow the below instructions to edit and delete a webpart. \u2022 Add a webpart \u2022 Edit webpart property \u2022 Remove a webpart \u2022 Run PowerShell script Add a webpart : Follow the below code to add a webpart to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221],"tags":[],"class_list":["post-6277","post","type-post","status-publish","format-standard","hentry","category-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add,Update &amp; Delete Webpart of a SharePoint Page Using PNP PowerShell - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add,Update &amp; Delete Webpart of a SharePoint Page Using PNP PowerShell - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, I have discussed about how to edit and delete a webpart of a SharePoint page using PNP PowerShell. Follow the below instructions to edit and delete a webpart. \u2022 Add a webpart \u2022 Edit webpart property \u2022 Remove a webpart \u2022 Run PowerShell script Add a webpart : Follow the below code to add a webpart to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-14T12:29:54+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add,Update & Delete Webpart of a SharePoint Page Using PNP PowerShell - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Add,Update & Delete Webpart of a SharePoint Page Using PNP PowerShell - Softree Technology","og_description":"In this blog, I have discussed about how to edit and delete a webpart of a SharePoint page using PNP PowerShell. Follow the below instructions to edit and delete a webpart. \u2022 Add a webpart \u2022 Edit webpart property \u2022 Remove a webpart \u2022 Run PowerShell script Add a webpart : Follow the below code to add a webpart to [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/","og_site_name":"Softree Technology","article_published_time":"2020-09-14T12:29:54+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Add,Update &#038; Delete Webpart of a SharePoint Page Using PNP PowerShell","datePublished":"2020-09-14T12:29:54+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/"},"wordCount":277,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/1.png","articleSection":["PowerShell"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/","url":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/","name":"Add,Update & Delete Webpart of a SharePoint Page Using PNP PowerShell - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/1.png","datePublished":"2020-09-14T12:29:54+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#primaryimage","url":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/1.png","contentUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/09\/1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/powershell\/addupdate-delete-webpart-of-a-sharepoint-page-using-pnp-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Add,Update &#038; Delete Webpart of a SharePoint Page Using PNP PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6277"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6277\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}