| By Corey Roth | Article Rating: |
|
| February 28, 2013 12:00 PM EST | Reads: |
419 |
My PowerShell posts always prove to be the most popular. I showed all sorts of cool PowerShell tricks in my talk back at SPC12. One of the things I covered was how to install and manage apps using PowerShell. Since there is a corporate catalog and SharePoint store, you might not think you need to install apps with PowerShell, but your developers may choose to the app model for a future internal project, so as an IT Pro you need to know how to install the thing. There are a lot of similarities to working with solution packages but there are several differences to be aware of. The documentation on TechNet is pretty good, but putting it all together can be tricky.
Specific to PowerShell, there is some terminology to familiarize yourself with. You’ll see these for parameter names so you need to know what they are otherwise you’ll find yourself confused.
- App Package – physical file containing the app (.app file)
- App – an instance of an app installed on a particular subsite
Along with the App, you’ll find an Id property that refers to a GUID of that particular app instance. We’ll talk about that more when it comes to updates.
To begin installing app, we first install the .app file into a site collection and then we deploy the app to an individual subsite. To install the app package, we use Import-SPAppPackage. Specify the path to your app package (.app file) with the –Path parameter. You’ll also need to specify which Site Collection will contain the app using the –Site parameter. Finally, the Source parameter tells SharePoint where the app came from (SharePoint Store, Corporate Catalog, or Object Model). I always specify a value of ObjectModel for my custom apps. Here’s what the command looks like. Assign the results of the command to variable so that you can use it in the next step.
$spapp = Import-SPAppPackage -Path .\spcdemoapp.app -Site http://server/sitecollection –Source ObjectModel
You can always add –confirm:$false to avoid getting prompted.
Now you have the AppPackage installed, you can deploy an instance of it to a subsite using Install-SPApp. You’ll need to provide a URL to the subsite using the –Web parameter and a reference to the imported app package. That’s why we saved the results of the last command into $spapp. Use the following command.
$instance = Install-SPApp -Web http://server/sitecollection/site -Identity $spapp
Like always with PowerShell, no news is good news. At this point, you should find the app installed on the Site Contents pages.
Here’s what it looks like it is running. This is mainly for reference when we start talking about updates.
To determine what apps are installed on a particular subsite use Get-SPAppInstance. This cmdlet can be executed three different ways. You need the id of the App Instance to update, export, or remove it. So often you combine it with a Where-Object command to get a reference to an app instance by name instead of by id.
$instance = Get-SPAppInstance -web http://server/sitecollection/site | Where-Object { $_.Title -eq "MyApp" }
Once you have a reference to the App Instance, removing the app from a subsite is easy with Uninstall-SPAppInstance.
Uninstall-SPAppInstance -Identity $instance
One nice feature of PowerShell is that you have the ability to export an installed app to a .app file using Export-SPAppPackage. It takes a parameter named -App. It expects the value from an instance called .App (so use Get-SPAppInstance as shown above). You also want to specify where to save the file using the –Path parameter.
Export-SPAppPackage –App $instance.App –Path .\ExportApp.app
When it comes to updating apps, that’s where things get a bit tricky. Here is what you need to do:
- Get a reference to the existing installed instance using Get-SPAppInstance shown earlier
- Import the new app package with Import-SPAppPackage
- Use Update-SPAppInstance with a reference to the imported app package and the existing instance
Here are the commands
$instance = Get-SPAppInstance -web http://server/sitecollection/site | Where-Object { $_.Title -eq "MyApp" }
$spappv2 = Import-SPAppPackage -Path .\myapp.app -Site http://server/sitecollection/site -Source ObjectModel
Update-SPAppInstance – Identity $instance –App $spappv2
One thing you might have noticed by now is that there is no way to retrieve which app packages are installed nor is there any way to remove them using PowerShell. This is a bit different than the way we deal with solution packages. I suspect it cleans itself up, but I’m really not sure. I hope these PowerShell commands prove to be useful to you. Let me know if you run into any issues.
Read the original blog entry...
Published February 28, 2013 Reads 419
Copyright © 2013 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Corey Roth
Corey Roth, a SharePoint Server MVP, is a consultant at Infusion specializing in SharePoint for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.
Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2010, .NET Framework 4.0, and Silverlight.
He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.
- Cloud People: A Who's Who of Cloud Computing
- Windows Azure IaaS Reaches General Availability
- Portable Experimenter’s Platform, Powered by Raspberry Pi
- Basho Announces Open Source Riak CS and General Availability of Riak CS Enterprise v1.3
- Predixion Software Announces General Availability of the Latest Version of its Predictive Analytics Platform
- Cloud Expo New York: Real-Time Analytics Using an In-Memory Data Grid
- Cloud Expo New York: The Big Challenge of Big Data & Hadoop Integration
- Agile Solutions for Cloud, Big Data, Mobility Services
- MicroStrategy Announces General Availability of MicroStrategy 9.3.1
- Cloud Computing: Cutting Costs, Boosting Profits
- AMAX Launches StorMax(TM) CFS, powered by IBM(R) General Parallel File System(TM) (GPFS(TM))
- Big Data: Visualizing the Strategic Business Imperative
- Cloud People: A Who's Who of Cloud Computing
- Examining the True Cost of Big Data
- Windows Azure IaaS Reaches General Availability
- Portable Experimenter’s Platform, Powered by Raspberry Pi
- SUSE Receives Common Criteria Security Certifications
- Basho Announces Open Source Riak CS and General Availability of Riak CS Enterprise v1.3
- Cloud Expo New York: Big Time - Introducing Hadoop on Azure
- Predixion Software Announces General Availability of the Latest Version of its Predictive Analytics Platform
- Cloud Expo New York: Real-Time Analytics Using an In-Memory Data Grid
- Book Excerpt: jQuery Essentials | Part 1
- Cloud Expo New York: The Big Challenge of Big Data & Hadoop Integration
- Help Desk Solution Empowers Employees
- The Top 250 Players in the Cloud Computing Ecosystem
- Web Services Using ColdFusion and Apache CXF
- Cloud People: A Who's Who of Cloud Computing
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Cloud Expo New York Call for Papers Now Open
- Eclipse "Pollinate" Project to Integrate with Apache Beehive
- An Introduction to Ant
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Beehive Code Now Available in Apache
- Apache's Tomcat 5.5 is First Release Ever to Use Eclipse JDT Java Compiler
- 4th International Cloud Computing Conference & Expo Starts Today
- "Beehive" Now Officially an Open Source Project: Apache Beehive

























