4

Can we deploy a SharePoint hosted app in Office 365 (SharePoint online) using PowerShell?

Like in SharePoint 2013 apps, we will import the .app file and then install it.

Can this be done in Office 365 also?

Please suggest some references.

3

Yes you can use Web.LoadAndInstallApp method

Please have a look at a little proof of concept below:

$url = "https://TestSite.sharepoint.com"
$username = "Testuser@testsite.sharepoint.com"
$password = "Lidf$ijsd@f$"
$appfilepath = "C:\temp\app.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
}
  • Thanks for the solution. I have tested this.It works only if the site is a developer site. Also, It doesnt install the App in App Catalog. Could you please help me with deploying into App Catalog? Is this possible? – user2598808 Mar 9 '15 at 12:53
0

For the app to deploy in non dev sites you need to buy a version, if your are running using trial accounts , you cannot do it. Microsoft provides to test the apps only in dev sites.

protected by Community Jan 29 '16 at 8:26

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.