Install and uninstall apps in SharePoint using powershell



Posted on October 14th, 2014

In this post you will learn how to install  and uninstall apps in SharePoint using powershell.

In App development article we have seen how to develop a basic SharePoint hosted app. Once we develop the app we need to deploy the app. So this post will help you to do that.

Install App:

To deploy the app we need to import the app once we publish it to the physical folder. After developing the app if we use publish option to publish it,  it will create a file with extension of app. For example if your app is MyfirstApp then the app package will be MyfirstApp.app.

To see more details inside the app, you can change the extension to ZIP and explore further.

In the below example we are importing the app details and setting into a variable.

This will done in two steps.

  • Import an app to site collection
  • Install the which has been imported


Import an app to site collection:

You need to use  Import-SPAppPackage command to import the app package.

# Import-SPAppPackage

$myspapp = Import-SPAppPackage -Path < Path to app > -Site < URL > -Source < Source >

Path to app : App package path in local system.

URL : URL for the site site collection which you want to import the app.

Source:  can be one of below

 Marketplace or CorporateCatalog, DeveloperSite, ObjectModel, RemoteObjectModel or InvalidSource.


# Example of using Import-SPAppPackage

$myapp = Import-SPAppPackage -Path "c:\deployment\MyfirstApp.app" -Site "http:\sharepoint-journey\appdevelopment" -Source ([microsoft.sharepoint.administration.spappsource]::DeveloperSite)

Install an app which has been imported:

Once you get the app details and you can use Install-SPapp command to install the app.

# Install-SPApp

Install-SPApp -Web < URL > -Identity $myapp

<URL> is URL for the site or sub site where you will install the App.

Uninstall App:

In the below example we will get all the Installed apps in a site collection or site.

# Get all the installed Apps

$installedapps = Get-SPAppInstance -Web < URL >

<URL> can be a site collection or a site

Then we will get the app which we want to uninstall from the list of apps.

# Get The app which need to be uninstall

$yourInstalledapp = $installedapps | where {$_.Title -eq '< app_title >'}

Finally uninstall the App using Uninstall-SPAppInstance command.

# Uninstall the App

Uninstall-SPAppInstance -Identity $yourInstalledapp

References:

If you want to Get all App instances for a specific App on a specific web application click here.

Remove all App instances for a specific App on a specific web application click here.



› install and uninstall apps in SharePoint using powershell



Join 6,500 subscribers and receive instant access to

Devendra's Library of Resources for SharePoint Developers

About Author

Devendra Velegandla is a four-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2017) for Office Servers and Services MVP and  SharePoint Server. He received the MCC award for his contributions in Microsoft MSDN/TechNet forums. He loves sharing articles, videos, and tutorial on SharePoint and Office 365.