0

I would like to remove default team site components such as: Quick links and news. So far I have been using Site design JSON schema to change navigation(remove, add new) on the left side.

Can this be done with a script and JSON schema ? Maybe it can be done in some other way e.g. with power shell ?

0

PnP PowerShell to Add Link to Quick Launch:

Add-PnPNavigationNode -Title "Contoso" -Url "http://contoso.sharepoint.com/sites/contoso/" -Location "QuickLaunch"

PnP PowerShell to Remove Link to Quick Launch:

Remove-PnPNavigationNode -Title Recent -Location QuickLaunch

Here is the PnP PowerShell script to add link to Quick Launch:

#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com/us"
 
#Get Credentials to connect
$Cred = Get-Credential
 
Try {
    #Connect to PNP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
     
    #Add a Link to Quick Launch Navigation
    Add-PnPNavigationNode -Title "Support Center" -Url "http://support.crescent.com" -Location "QuickLaunch"
 
    #Get the Navigation node "Support Center"
    $ParentID = Get-PnPNavigationNode -Location QuickLaunch | Where {$_.Title -eq "Support Center"}  | Select -ExpandProperty ID
    #Add a link under "Support Center
    Add-PnPNavigationNode -Title "Application Support" -Url "http://support.crescent.com/apps" -Location "QuickLaunch" -Parent $ParentID
  
    Write-host "Quick Launch Links Added Successfully!" -f Green
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

More information, please refer to the following articles:

========================== Updated Answer =========================

Please run the following PnP PowerShell script:

#Connect to Site
$SiteURL = "https://domain.sharepoint.com/sites/Echo"
$Cred = Get-Credential
Connect-PnPOnline -Url $SiteURL -Credentials $Cred

#Retrieve all web parts used in modern site pages.
$page = Get-PnPClientSidePage -Identity "Home.aspx"
$WebParts = $page.Controls

# if there are more than one webparts  
foreach($webpart in $webparts){  
       Write-Host "Title: " $webpart.Title 
       Write-Host "WebPart Id:  " $webpart.InstanceId    
} 

enter image description here

Then, please run the following command to remove webpart.

#Remove webpart 
Remove-PnPClientSideComponent -Page $page -InstanceId 418ba70b-4cf7-410a-a5fd-ea38386915ac

enter image description here

2
  • Unfortunately, I'm not talking about navigation. I mean the parts of the site that are there when you enter Home. These are two default Web Part Quick links and news. I tried to use this script but after login I get 403 code .sharepointdiary.com/2017/05/…
    – Jelon3k
    Apr 13 '21 at 8:26
  • Hi, Jelon3k. Thanks for your reply. I have updated answer under initial My Answer. Hope this can help you to solve issue. Have a nice day! Apr 14 '21 at 9:04
0

It does what it needs to do

try {​​​​​​​​  

Connect-PnPOnline-Urlhttps://yourname.sharepoint.com/sites/yourSite $page=Get-PnPClientSidePage-Identity"Home.aspx" #Retrieve webparts from modern page
$webParts=$page.Controls foreach($webpartin$webparts) {​​​​​​​​
Write- Host "WebPart Id " $webpart.InstanceId Write- Host "Title " $webpart.Title }​​​​​​​​
Remove-PnPClientSideComponent-Page$page-InstanceId Your Id }​​​​​​​​ catch {​​​​​​​​
Write- Host - ForegroundColor Red 'Error ',':' $Error[0].ToString();
sleep10 }​​​​​​​​

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.