question

RS-7668 avatar image
0 Votes"
RS-7668 asked RS-7668 commented

PnP PowerShell commands for set theme, remove sections of page and uninstall app not working

In the newest version of pnp powershell (1.7.0), I am trying these commands


Changing theme to one of the out of the box ones

Set-PnPWebTheme -Theme "Teal"

But if I use a name of a custom theme I've deployed, it works



Remove sections of the page

$pg = Get-PnPPage -Identity "Home"
$sectionsCount = $pg.Sections.Count
for($i=$sectionsCount-1; $i -ge 0; $i--) {
write-host $i
$pg.Sections.RemoveAt($i)
}
$page = Set-PnPPage -Identity $pg -Publish



Remove an add-in (spfx extension) from a site (not app catalogue)

Uninstall-PnPApp -Identity 150520F1-9488-423C-8006-AC541078B029



But they all do not work. The first one gives a unknown error. The other two does nothing.

Does anyone know what's wrong?

office-sharepoint-onlinesharepoint-devoffice-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered

Hi @RS-7668 ,
There might be some mistake in your cmdlet
Changing theme to one of the out of the box ones

 Set-PnPWebTheme -Theme MyTheme

or

 Get-PnPTenantTheme -Name "MyTheme" | Set-PnPWebTheme

to set the theme named "MyTheme" to the current web.

Remove sections of the page

 $pg = Get-PnPPage -Identity "Home"
 $sectionsCount = $pg.Sections
 for($i=$sectionsCount-1; $i -ge 0; $i--) {
 write-host $i
 $pg.Sections.RemoveAt($i)
 }
 $page = Set-PnPPage -Identity $pg -Publish

Remove an add-in (spfx extension) from a site (not app catalogue)

 Uninstall-PnPApp -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe

or

 Uninstall-PnPApp -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Site

It seems your Identity ID format a little different with the example.Please check your app id.

All pnp powershell cmdlets for refer:
https://pnp.github.io/powershell/cmdlets/Uninstall-PnPApp.html


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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RS-7668 avatar image
0 Votes"
RS-7668 answered RS-7668 commented

Tried it. See my exact code

 Connect-PnPOnline -Url "https://mysite.sharepoint.com/sites/TestSite" -Interactive
 Get-PnPTenantTheme -Name "Teal" | Set-PnPWebTheme

this produces

 Get-PnPTenantTheme : Unknown Error
 At C:\SPOnline\Templates\clear_site.ps1:19 char:1
 + Get-PnPTenantTheme -Name "Teal" | Set-PnPWebTheme
 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : WriteError: (:) [Get-PnPTenantTheme], ServerException
     + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Admin.GetTenantTheme


Ans for removing sections of the page


 Connect-PnPOnline -Url "https://mysite.sharepoint.com/sites/TestSite" -Interactive
 $pg = Get-PnPPage -Identity "Home"
 $sectionsCount = $pg.Sections.Count
 for($i=$sectionsCount-1; $i -ge 0; $i--) {
     write-host $i
     $pg.Sections.RemoveAt($i)
 }
 $page = Set-PnPPage -Identity $pg -Publish
    
 Disconnect-PnPOnline


It prints out 1 and then 0 (as I have 2 sections on the page). But then If I refresh the page, the sections are still on the page.



And for the last command

 Uninstall-PnPApp -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Site

I don't need -Scope Site as that is if the addin comes from a site collection app catalogue. Mine comes from the tenant app catalogue.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That is not what I am using. That is management Shell. I am using PnP Powershell https://pnp.github.io/powershell/cmdlets/Add-PnPAlert.html

0 Votes 0 ·