Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. param
  2. (
  3. [string]$AppCatalogUrl,
  4. [string]$TargetSiteUrl,
  5. [string]$AppName
  6. )
  7.  
  8. if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
  9. Add-PSSnapin "Microsoft.SharePoint.PowerShell";
  10. }
  11.  
  12. $appCatalog = Get-SPWeb $AppCatalogUrl;
  13. if ($appCatalog -eq $null) {
  14. throw "App Catalog Site does not exist at ${AppCatalogUrl}";
  15. }
  16.  
  17. $targetSite = Get-SPWeb $TargetSiteUrl;
  18. if ($targetSite -eq $null) {
  19. throw "Target Site does not exist at ${TargetSiteUrl}";
  20. }
  21.  
  22. $appList = $appCatalog.Lists.TryGetList("Apps for SharePoint");
  23. $appCatalogAppItem = $null;
  24. if ($appList -ne $null) {
  25. $appCatalogAppItem = $appList.Items | ?{$_.Title -eq $AppName};
  26. if ($appCatalogAppItem -eq $null){
  27. throw "{$AppName} does not exist in the app catalog";
  28. }
  29. }
  30.  
  31. $appGuid = $appCatalogAppItem["Product ID"].Replace("{","").Replace("}","");
  32. $siteCollection = $targetSite.Site;
  33. foreach ($web in $siteCollection.AllWebs)
  34. {
  35. $appInstances = Get-SPAppInstance -Web $web;
  36. foreach ($instance in $appInstances)
  37. {
  38. if ($instance.App.ProductId -eq $appGuid)
  39. {
  40. $stream = $appCatalogAppItem.File.OpenBinaryStream();
  41. $instance.Upgrade($stream);
  42. $stream.Close();
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment