Forum Discussion

katnew's avatar
katnew
Copper Contributor
Mar 10, 2020

SPO App Uninstall Scope Web

Hi all,

 

I need to bulk Remove/Uninstall a particular App installed to 100+ subsites (web).

Uninstall-PnpApp can only be scoped to Tenant or Site Collection.

Is it possible to scope to the Subsite? 

 

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/uninstall-pnpapp?view=sharepoint-ps

https://pnp.github.io/office365-cli/cmd/spo/app/app-uninstall/

  • katnew 

     

    I didn`t test this,However you can loop through all the subsites underneath the site collection and uninstall the app in the below way.

    # Input Parameters
    $credentials=Get-Credential
    $URL="https://yoursites.sharepoint.com"

    # Connect to SharePoint Online
    Connect-PnPOnline -Url $URL -Credentials $credentials

    # Get the site collections
    $siteColl=Get-PnPTenantSite

    # Loop through the site collections
    foreach($site in $siteColl)
    {


    Connect-PnPOnline -Url $site .Url -Credentials $cred
    Get-PnPSubWebs | ForEach-Object{
    spo app uninstall --id <<Your APP ID>> --siteUrl $_.Url
    }
    }

     

    Please test in your dev environment first.

  • O365Developer's avatar
    O365Developer
    Brass Contributor

    katnew 

     

    I didn`t test this,However you can loop through all the subsites underneath the site collection and uninstall the app in the below way.

    # Input Parameters
    $credentials=Get-Credential
    $URL="https://yoursites.sharepoint.com"

    # Connect to SharePoint Online
    Connect-PnPOnline -Url $URL -Credentials $credentials

    # Get the site collections
    $siteColl=Get-PnPTenantSite

    # Loop through the site collections
    foreach($site in $siteColl)
    {


    Connect-PnPOnline -Url $site .Url -Credentials $cred
    Get-PnPSubWebs | ForEach-Object{
    spo app uninstall --id <<Your APP ID>> --siteUrl $_.Url
    }
    }

     

    Please test in your dev environment first.

    • katnew's avatar
      katnew
      Copper Contributor

      Thanks O365Developer !

      Just looping back to this post, I did a little something like this:

      $App = Get-PnPAppInstance -Identity $ID | Select-Object AppWebFullUrl, Id, Status, Title, WebId, SiteId
      If ($App -ne $null) {
      Uninstall-PnPAppInstance -Identity $ID -Force
      }

      Pretty much the same, but using the PnP commands ❤️  

Resources