PowerShell script – Enlist all apps in my site collection installed from marketplace or app catalog using PnP PowerShell

PowerShell - Filtering custom apps - installed from either marketplace or app catalog
PowerShell - Filtering custom apps - installed from either marketplace or app catalog

Hi All,

Greetings for the day!

Today, I am sharing one more very useful PowerShell script. How to enlist all installed apps in my site collection either from marketplace or app catalog.

Use case

  • Microsoft recently stopped enabling of custom scripting. We have detailed article for the same. Microsoft 365 – Major Update – Removal of Custom Script setting in OneDrive and SharePoint web https://knowledge-junction.in/2024/02/26/m365updatecustomscriptsetting/  
  • In our tenant, we have used third party webpart – “Modern Script Editor” webpart.
  • These “Modern Script Editor” web part requires custom scripting enabled.
  • Though Microsoft declared that existing “Modern Script Webpart” doesn’t get affected, we through to replace them either with OOB webpart or we can write our custom SPFX webpart.
  • Before start implementation we thought to do impact analysis. So, one point is to enlist all the site collections and site pages within those, where the “Modern Script Editor” webpart is added.
  • Hence this PowerShell script born.

PowerShell script – How to enlist all the installed apps either from marketplace or app catalog in my Site Collection.

Detailed PowerShell script steps

  • Specifying the URL of Site Collection from which we need to get all installed apps.
$Url = "https://knowledgejunction1.sharepoint.com/"
  • Get the credentials to connect to the Site Collection using – Get-Credential
$Credentials = Get-Credential 
  • Connect to the Site collection using – Connect-PnPOnline
Connect-PnPOnline –Url $Url –Credentials $Credentials
  • Get the web object including AppTiles using – Get-PnPWeb
$web = Get-PnPWeb –Includes AppTiles
  • Get all AppTiles
$appTiles = $web.AppTiles
Invoke-PnPQuery
  • In SharePoint online, everything is app so we will get all the list/libraries as shown in figure below.

PowerShell - All app types
fig : PowerShell – All app types
  • Please notice, OOB SharePoint apps(list, libraries) has “AppPrincipalId” as null or empty as shown in above image.
  • Apps which are installed from MarketPlace or app catalog, have “AppPrincipalId”.
  • So, we could have condition if “AppPrincipalId” is not null, then the app is custom app as
if($appTile.AppPrincipalId -ne ''){
        $appTile | Format-Table -AutoSize -Property Title, AppType, AppPrincipalId
    } 

PowerShell - Filtering custom apps - installed from either marketplace or app catalog
fig : PowerShell – Filtering custom apps – installed from either marketplace or app catalog

App Types

  • Doclib          
  • List
  • Tenant         
  • Instance      
  • Feature       
  • CommonList

COMPLETE SCRIPT

<#
.SYNOPSIS
  Get-InstalledApps generates a report of installed apps in my site collection either from appcatalog or marketplace.
 
.DESCRIPTION 
  This script get all apps from the given site collection. Script verifies if app have AppPrincipalId is available or not
  If AppPrincipalId is available means, the app is installed from app catalogue or marketplace. Output is shown in console.
   
.EXAMPLE
  Get-InstalledApps
 
.EXAMPLE
  Get-InstalledApps
 
#>

#site collection URL from which we need to get installed app
$Url = "https://knowledgejunction1.sharepoint.com/"

#get the credentials
$Credentials = Get-Credential

#connect to the site
Connect-PnPOnline –Url $Url –Credentials $Credentials

#get instance of web object
$web = Get-PnPWeb –Includes AppTiles

#get all apss
$appTiles = $web.AppTiles

Invoke-PnPQuery

#traversing through all apps
foreach($appTile in $appTiles){

    #condition to make sure App is not SharePoint OOB object
    if($appTile.AppPrincipalId -ne ''){
        $appTile | Format-Table -AutoSize -Property Title, AppType, AppPrincipalId
    } #if

}#foreach

We have good amount of PowerShell articles, more than 200+ PowerShell script. Please have a look at PowerShell tutorial – https://knowledge-junction.in/category/technology-articles/powershell-tutorial/

REFERENCES

Thank you for reading 😊 Stay tuned for more such articles.

If you like this article or useful to you, kindly share and subscribe Knowledge-Junction.

Have a FANTASTIC time ahead! LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading