Add-PnPClientSideWebPart not working in Sharepoint online

Copper Contributor

I am trying to add a new webpart (document library) using Add-PnPClientSideWebPart.

I am using following code :

 

 

Set-Variable -Name "NewDocLib" -Value ((Get-PnPList -Identity "NewDocLib").Id)
Add-PnPClientSideWebPart -Page "Home" -Component $NewDocLib -Section 1 -Column 2 -Order 1

 

 

This is as per following article : 

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpclientsidewebpart?view=shar...

 

I am getting following error :

 

 

Add-PnPClientSideWebPart : Value cannot be null.
Parameter name: Passed in component cannot be null
At line:1 char:1
+ Add-PnPClientSideWebPart -Page "Home" -Component $NewDocLib -Section  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-PnPClientSideWebPart], ArgumentNullException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.WebParts.AddClientSideWebPart

 

 

Can I get some help?

1 Reply
looking at the error variable $NewDocLib is null
it seems Get-PnPList -Identity "NewDocLib").Id is not returning anything
what do you see if you add write-host "$($NewDocLib)" after line 1 and before line 2