Saturday, May 11, 2013

Install and uninstall SharePoint Apps using PowerShell


Microsoft introduced apps for Office and apps for SharePoint. You can develop Apps using visual studio office tools and NAPA. You can deploy app from visual studio deploy option or through PowerShell.
Here is how PowerShell can help you deploy Apps to different site collections.
To Install SharePoint App -
Before you can install an app, make sure that App is published to a physical folder using publish option. After publishing you will have a package file with .app extension (like yourApp.app).  
Installation of app is two steps process, first import app to a site collection and then install imported App.
Import-SPAppPackage -Path <Path of .app file> -Site < SiteCollectionURL > -Source < AppSource>
AppSource can be Marketplace, CorporateCatalog, DeveloperSite, ObjectModel, RemoteObjectModel.
Install-SPApp -Web <SPweb ID or URL> -Identity <SPApp>
Example:
$myApp = Import-SPAppPackage -Path "c:\Apps\MySharepointApp.app" -Site http://localhost/apps
 -Source ([microsoft.sharepoint.administration.spappsource]::ObjectModel)

Install-SPApp -Web http://localhost/apps -Identity $myApp
To Uninstall SharePoint App -
To uninstall an app first you need to get the instances of installed Apps then get the app you want to uninstall using app ID or app Title.
To get all installed apps in SharePoint site -
$appInstances = Get-SPAppInstance -Web < SiteCollectionURL >
To get the app details that you want uninstall -
$app = $appInstances | where {$_.Title -eq '< Title or ID of App >'}
To uninstall the app -
Uninstall-SPAppInstance -Identity $app
Example:
$appInstances = Get-SPAppInstance -Web http://localhost/apps
$app = $appInstances | where {$_.Title -eq ' Your SharePoint App'}
Uninstall-SPAppInstance -Identity $app

No comments:

Post a Comment