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.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityYes 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
}
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.