SharePoint On-Premises : PowerShell script to find out app instances from all webs of all Site Collection in a Web Application

SharePoint On-Premises - PowerShell script to enlist all webs where given app is instantiated
SharePoint On-Premises - PowerShell script to enlist all webs where given app is instantiated

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

SharePoint migration continues. Today sharing one more small PowerShell script required in SharePoint migration

Background :

  • We are in process of migration of our SharePoint 2013 application to SharePoint online (Microsoft 365)
  • One of the step / process in this migration is to analyze the customizations
  • We have one custom app is installed in app catalog of SharePoint 2013 on-premises environment
  • Since this app is very old we need to confirm with the owners of the site where this app is instantiated/ used
  • Because of above requirement this PowerShell script born 🙂 – Enlist all the web where given app is installed 🙂

Step by step PowerShell script :

fig : SharePoint On-Premises - App catalog site collection where app is installed
fig : SharePoint On-Premises – App catalog site collection where app is installed – app details including App Title, App Name, App ID, App Owner details, App modified date
  • Add the snap in for SharePoint PowerShell
#Add snap in for SharePoint PowerShell 
Add-PsSnapin Microsoft.SharePoint.PowerShell

  • Get the app title of the app
  • We will get all app details including app Title, app Name, app Id, app Owner from the App Catalog site collection as shown in above fig
#app title which we need to find
$appTitle = "My app title"

  • We will loop through each site collection in our Web Application
  • Then we will loop each web for each site collection
  • We will use Get-SPAppInstance PowerShell CMDLET to get the app instance
  • Syntax Get-SPAppInstance
Get-SPAppInstance
   -Identity <SPAppInstance>
   [-AssignmentCollection <SPAssignmentCollection>]
   [<CommonParameters>]

Get-SPAppInstance
   [-App <SPApp>]
   [-AssignmentCollection <SPAssignmentCollection>]
   -Web <SPWebPipeBind>
   [<CommonParameters>]

Examples :

  • Get collection of all apps installed on given web
Get-SPAppInstance -Web https://knowledgejunction.sharepoint.com
#fetch the app instance if it matches with our app 
$appInstance = Get-SPAppInstance -Web $web.Url  | Where{$_.Title -eq $appTitle}

Complete Script :

#PowerShell to find the app instances - lists all the web URLs where given app is installed in my web application

#Add snap in for SharePoint PowerShell 
Add-PsSnapin Microsoft.SharePoint.PowerShell

#app title which we need to find
$appTitle = "My app title"

#my web application url
$rootUrl = "https://knoweldgejunction.sharepoint.com/"

#get the web application 
$webApp = Get-SPWebApplication $rootUrl

#loop through all site collection in web application
foreach($site in $webApp.Sites){

    #loop through all the webs from respective site collection
    foreach($web in $site.AllWebs){

        #fetch the app instance if it matches with our app 
        $appInstance = Get-SPAppInstance -Web $web.Url  | Where{$_.Title -eq $appTitle}

        if($appInstance -ne $null){

            #writting the respective URL in console - we can get this list in either CSV or TEXT file
            Write-Host $web.Url -BackgroundColor Green

            Write-Host $appInstance.App.VersionString -BackgroundColor Cyan

        }#if($appInstance -ne $null){

    }#foreach($web in $site.AllWebs){
}#foreach($site in $webApp.Sites){
SharePoint On-Premises  - PowerShell script to enlist all webs where given app is instantiated
fig : SharePoint On-Premises – PowerShell script to enlist all webs where given app is instantiated

Thanks 🙂 STAY SAFE 🙂 STAY HEALTHY 🙂

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