none
Update all apps in a site collections through SharePoint Management Shell?

    Question

  • Hi,

    Is there a way by using Powershell in SharePoint Online Management Shell to update all apps in a site collection? That is we have new versions of the apps in the app catalog and need to update them in the site collections. We have about 20 site collections with 15 apps in each, so a total of 300 apps that need to be updated. It will take us long time to do it manually unless we find a way via Powershell and SharePoint Online Management Shell.

    Thanks!

    Johan

    Tuesday, February 14, 2017 11:11 AM

All replies

  • Hi,

    Here is the solution for your reference.

    https://blog.sprider.org/2015/02/05/o365-sharepoint-online-load-and-install-app-using-csom-powershell/

    $url = "https://xxx.sharepoint.com/sites/lee"
    $username = "user@xxx.onmicrosoft.com"
    $password = "pw"
    $appfilepath = "C:\Lee\AppToDeploy\SharePointAppLee.app"
    $Password = $password |ConvertTo-SecureString -AsPlainText -force
    
    try
    {
        Write-Host "Load CSOM DLLs" -foregroundcolor black -backgroundcolor yellow Set-Location
        $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
        $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
        Write-Host "CSOM DLLs loaded succeefully" -foregroundcolor black -backgroundcolor Green
    }
    catch
    {
        Write-Host "Problem in loading CSOM DLLs : $_.Exception.Message" -foregroundcolor black -backgroundcolor Red
        return
    }
    
    try
    {
        Write-Host "Authenticate tenant site $url and get ClientContext object" -foregroundcolor black -backgroundcolor yellow
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
        $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
        $context.Credentials = $credentials
        $web = $context.Web
        $site = $context.Site
        $context.Load($web)
        $context.Load($site)
        $context.ExecuteQuery()
        Write-Host "Authentication to online site $url and get ClientContext DLLS succeeful" -foregroundcolor black -backgroundcolor Green
    }
    catch
    {
        Write-Host "Unable to authenticate to online site. Error : $_.Exception.Message" -foregroundcolor black -backgroundcolor Red
        return
    }
    
    try
    {
        $appIoStream = New-Object IO.FileStream($appfilepath,[System.IO.FileMode]::Open)
        $appInstance = $web.LoadAndInstallApp($appIoStream) | Out-Null
        $context.ExecuteQuery()
        Write-Host $appInstance.Id
    }
    catch
    {
        Write-Host "Unable to Install App Error : $_.Exception.Message" -foregroundcolor black -backgroundcolor Red
        return
    }

    You may need this.

    https://blogs.msdn.microsoft.com/officeapps/2013/12/10/enable-app-sideloading-in-your-non-developer-site-collection/

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 15, 2017 3:55 AM
  • Thanks, but this script does not really simplyfy that much for me - with that script I need to specify one specific file and one specific site collection, and that is more or less the same way as doing this manually by updating the app in that site collection. What I would need is a script that iterates through the app catalog and update a specific site collection (or all site collections) with a new version of the apps already existing in the site collection.

    Best regards

    Johan


    Wednesday, February 15, 2017 9:28 AM
  • Hi,

     

    You may try to iterate over the site collections and app instances and then upgrade, here are some links for your reference.

     

    https://social.technet.microsoft.com/Forums/office/en-US/a9860213-3f27-4c43-b8ac-a9301b756752/sp-online-list-all-site-collections-and-subsites-using-powershell-sharepoint-online-management?forum=sharepointgeneral

    https://social.technet.microsoft.com/wiki/contents/articles/33269.get-spoappinfo-sharepoint-online-powershell-csom.aspx

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, February 17, 2017 10:00 AM