1
$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
}

I got a error when run this script. The error is executequery with 0 argument. The remote server returned error: 403 forbiddden. I try to figure out. If I using sharepoint online mangement shell, It can pass this error but loadandinstall app run too long, so much time but return no result. Then, I try to config to use windows powershell. I installed Azure Actice Dicretory,.. Imported module MsOnline, Connect-SPOService successfully. but It still raise this error( 403 forbidden). I added the permisson to the site collection, too. But I could not deploy app to it. Thanks for reading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.