{"id":6160,"date":"2020-07-06T14:36:09","date_gmt":"2020-07-06T14:36:09","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6160"},"modified":"2020-07-06T14:36:09","modified_gmt":"2020-07-06T14:36:09","slug":"create-modern-page-and-add-webpart-to-it-using-pnp-powershell","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/","title":{"rendered":"Create Modern Page and Add Webpart to It Using PnP PowerShell"},"content":{"rendered":"\n<p>In this blog, we will discuss how we can create a modern site Page programmatically using PnP online. Then we will add a hero Webpart programmatically to it. To perform the procedure, we must follow the below steps.<\/p>\n\n\n\n<p><strong>Step-1: &#8211; <\/strong>First, we have to open the windows PowerShell and then run the command<em> \u201cConnect-PnPOnline -Url &nbsp;&nbsp;providesiteUrl\u201d. <\/em>Then run ISE as administrator as shown below (Right click on windows PowerShell).<\/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\/07\/1.png\" alt=\"\" class=\"wp-image-6161\" width=\"164\" height=\"218\"\/><\/figure>\n\n\n\n<p><strong>Step-2: &#8211; <\/strong>Store site URL in an object siteURL. Then connect PnP online and ask for the credential as shown in the below code. <\/p>\n\n\n\n<p><em># Provide URL of the Site over here&nbsp;&nbsp;&nbsp; $siteURL<\/em> = <a href=\"https:\/\/sharepoint.com\/sites\/sitename\"><em><span style=\"text-decoration: underline;\">https:\/\/sharepoint.com\/sites\/sitename<\/span><\/em><\/a><\/p>\n\n\n\n<p># If you do not wish to pass credentials hard coded then you can use:<em> -Credentials (Get-Credential).<\/em> &nbsp;This will prompt to enter credentials&nbsp;   <em>Connect-PnPOnline -Url $siteURL<\/em> &#8211;<em>Credentials (Get-Credential)<\/em>. Provide valid credential for SharePoint site.<\/p>\n\n\n\n<p><strong>Step-3: &#8211; <\/strong>Here, we are going to create a modern site page having title <em>\u201cHomepage\u201d<\/em> by using command<em> \u201cAdd-PnPClientSidePage\u201d.<\/em><\/p>\n\n\n\n<p><strong>Step-4: &#8211; <\/strong>We will add a section to the page by using the command  <strong><em>\u201c<\/em><\/strong><em>Add-PnPClientSidePageSection<\/em><strong><em>\u201d<\/em><\/strong><em>.<\/em><\/p>\n\n\n\n<p><strong>Step-5: &#8211; <\/strong>Now in the last step, we will add a hero webpart to the page which we have created. Here, for this we require the below command <strong><em>\u201c<\/em><\/strong><em>Add-PnPClientSideWebPart<\/em><strong><em>\u201d<\/em>. <\/strong> Now, please follow the below code snippet present in the image for the complete coding.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Provide URL of the Site over here\n$siteURL = \"https:\/\/sharepoint.sharepoint.com\/sites\/Site\"\n# If you do not wish to pass credentials hard coded then you can use: -Credentials (Get-Credential). This will prompt to enter credentials\nConnect-PnPOnline -Url $siteURL -Credentials (Get-Credential)\n#Create Site Page\n$page = Add-PnPClientSidePage  -Name \u201cPageName\u201d\n#Add a new sections to the page \nAdd-PnPClientSidePageSection -Page $page -SectionTemplate OneColumn -Order 1 # OneColumnFullWidth is only available if the site is a Communication site\n#Add Hero webpart to page  \nAdd-PnPClientSideWebPart -Page $page -DefaultWebPartType \"Hero\" -Section 1 -Column 1<\/code><\/pre>\n\n\n\n<p>After running the code, we\nneed to check site content of the provided site and we will see that a page has\nbeen created successfully as shown below.<\/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\/07\/2.png\" alt=\"\" class=\"wp-image-6162\" width=\"239\" height=\"183\"\/><\/figure>\n\n\n\n<p>Finally after opening the site page, go to the edit mode to check the hero Webpart.<\/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\/07\/3-1024x436.png\" alt=\"\" class=\"wp-image-6163\" width=\"760\" height=\"323\"\/><\/figure>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\"><em>Keywords:<\/em><\/span><\/strong><br> \u2022    Create Modern site page and add a Webpart to it using PnP Powrshell.<br> \u2022    Creating Modern Page and add hero Webpart using PnP online.<br> \u2022    How to create Modern site page using Pnp Powershell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will discuss how we can create a modern site Page programmatically using PnP online. Then we will add a hero Webpart programmatically to it. To perform the procedure, we must follow the below steps. Step-1: &#8211; First, we have to open the windows PowerShell and then run the command \u201cConnect-PnPOnline -Url &nbsp;&nbsp;providesiteUrl\u201d. Then run ISE as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[298],"tags":[],"class_list":["post-6160","post","type-post","status-publish","format-standard","hentry","category-pnp-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Modern Page and Add Webpart to It 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\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Modern Page and Add Webpart to It Using PnP PowerShell - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, we will discuss how we can create a modern site Page programmatically using PnP online. Then we will add a hero Webpart programmatically to it. To perform the procedure, we must follow the below steps. Step-1: &#8211; First, we have to open the windows PowerShell and then run the command \u201cConnect-PnPOnline -Url &nbsp;&nbsp;providesiteUrl\u201d. Then run ISE as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-06T14:36:09+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=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Modern Page and Add Webpart to It 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\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Create Modern Page and Add Webpart to It Using PnP PowerShell - Softree Technology","og_description":"In this blog, we will discuss how we can create a modern site Page programmatically using PnP online. Then we will add a hero Webpart programmatically to it. To perform the procedure, we must follow the below steps. Step-1: &#8211; First, we have to open the windows PowerShell and then run the command \u201cConnect-PnPOnline -Url &nbsp;&nbsp;providesiteUrl\u201d. Then run ISE as [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/","og_site_name":"Softree Technology","article_published_time":"2020-07-06T14:36:09+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Create Modern Page and Add Webpart to It Using PnP PowerShell","datePublished":"2020-07-06T14:36:09+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/"},"wordCount":312,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/07\/1.png","articleSection":["PnP PowerShell"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/","url":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/","name":"Create Modern Page and Add Webpart to It Using PnP PowerShell - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/07\/1.png","datePublished":"2020-07-06T14:36:09+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#primaryimage","url":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/07\/1.png","contentUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/07\/1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/pnp-powershell\/create-modern-page-and-add-webpart-to-it-using-pnp-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Modern Page and Add Webpart to It 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\/6160","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=6160"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6160\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}