This 'Get-PnPClientSideComponent' command is not giving webparts of home page without editing

Jyoti Rajpurohit 21 Reputation points
2021-06-13T15:01:55.03+00:00

Hello,

I have newly created page using home as layout, it has default webparts so we need to remove web parts from the page using powershell, but to remove webparts, we need InstanceId of webparts

I used cmd - Get-PnPClientSideComponent -Page Home

It displayed blank. So, I went to the Home page and manually edited and republished the page and then run the command, I got the list of client web parts.

I have to achieve this without manually edit the page.

I also tried cmd - Set-PnPClientSidePage -Identity "Home" -Publish -LayoutType Home
- Set-PnPClientSidePage -Identity "Home" -Publish

still it gives empty output ..

Thank you

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. JoyZ 18,111 Reputation points
    2021-06-14T07:16:22.977+00:00

    @Jyoti Rajpurohit ,

    Please use 'Get-PnPPageComponent' instead of Get-PnPClientSideComponent, since the alias 'Get-PnPClientSideComponent' will be removed in the 1.5.0 release.

    Get-PnPPageComponent -Page Home  
    

    In addition, please note that for a newly created modern site, the Home.aspx page will not be returning any components.

    This is because the underlying CanvasContent1 will not be populated until the homepage has been edited and published.

    The reason for this behavior is to allow for the default homepage to be able to be updated by Microsoft as long as it hasn't been modified.

    For any other site page or after editing and publishing the homepage, this command will return the correct components as they are positioned on the site page.

    For more information, please refer to:

    https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnppagecomponent?view=sharepoint-ps


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Jyoti Rajpurohit 21 Reputation points
    2021-06-23T15:30:21.347+00:00

    Hi @JulieWang-MSFT

    Yes Sure !!

    we have to run 2 cmds only

    Create a page using Home as layout

    Step 1:

    Add-PnPClientSidePage -Name "Home1" -LayoutType Home
    

    Add the webparts(1,2,3...) all you want to add, I added 2 webparts.

    Step 2:

    Add-PnPClientSideWebPart -Page "Home1" -Component "Search"
    Add-PnPClientSideWebPart -Page "Home1" -Component "SearchCompany"
    

    Step 3:

    Get-PnPClientSideComponent -Page Home1
    

    You will get the list of webparts that you have added, it automatically removed the default webparts when you add it.

    Thank You :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.