Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param
- (
- [string]$AppCatalogUrl,
- [string]$TargetSiteUrl,
- [string]$AppName
- )
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
- Add-PSSnapin "Microsoft.SharePoint.PowerShell";
- }
- $appCatalog = Get-SPWeb $AppCatalogUrl;
- if ($appCatalog -eq $null) {
- throw "App Catalog Site does not exist at ${AppCatalogUrl}";
- }
- $targetSite = Get-SPWeb $TargetSiteUrl;
- if ($targetSite -eq $null) {
- throw "Target Site does not exist at ${TargetSiteUrl}";
- }
- $appList = $appCatalog.Lists.TryGetList("Apps for SharePoint");
- $appCatalogAppItem = $null;
- if ($appList -ne $null) {
- $appCatalogAppItem = $appList.Items | ?{$_.Title -eq $AppName};
- if ($appCatalogAppItem -eq $null){
- throw "{$AppName} does not exist in the app catalog";
- }
- }
- $appGuid = $appCatalogAppItem["Product ID"].Replace("{","").Replace("}","");
- $siteCollection = $targetSite.Site;
- foreach ($web in $siteCollection.AllWebs)
- {
- $appInstances = Get-SPAppInstance -Web $web;
- foreach ($instance in $appInstances)
- {
- if ($instance.App.ProductId -eq $appGuid)
- {
- $stream = $appCatalogAppItem.File.OpenBinaryStream();
- $instance.Upgrade($stream);
- $stream.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment