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.

2 Answers 2

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 = "[email protected]"
$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
}
1
  • 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? Mar 9, 2015 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.

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