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

RS 21 Reputation points
2021-08-30T13:42:42.333+00:00

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?

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,481 Reputation points Microsoft External Staff
    2021-08-31T02:34:43.077+00:00

    Hi @RS ,
    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.

    0 comments No comments

  2. RS 21 Reputation points
    2021-08-31T14:51:44.827+00:00

    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.


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.