try
{
Write-Host "Load XML config file" -foregroundcolor black -backgroundcolor yellow
$xdoc = [xml] (get-content "C:\\config.xml")
$url = $xdoc.Tenant.Admin.site $username = $xdoc.Tenant.Admin.username $password = $xdoc.Tenant.Admin.password $appfilepath = $xdoc.Tenant.appfilepath $Password = $password |ConvertTo-SecureString -AsPlainText -force
Write-Host "Global variables loaded succeefully" -foregroundcolor black -backgroundcolor Green } catch { Write-Host "Problem in loading the XML or parsing the variables : $_.Exception.Message" -foregroundcolor black -backgroundcolor Red return }
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
}
$appIoStream = New-Object IO.FileStream("C:\\TestApp.app" ,[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
}
Read Next
O365 / SharePoint Online – Import Term Store Terms using CSOM & PowerShell
Provider Hosted App Deployment to Azure Website’s (One Azure site for multiple apps)
Tags
AAD
API
AWS
AWS Comprehend
Actions
Angular
Ansible
Automation
Azure
Azure CLI
BDC
Bash
Bible API
Bitbucket
Bot
CLI for Microsoft 365
CSOM
Citrix
Cloud
Cloud Watch
CloudWatch
CodeWhisperer
Computer Vision API
Copilot
Data Extraction
DevOps
Dotnet
Elastic Transcoder
EventBridge
Faith
GCP
GenAI
GitHub
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
InfoPath
JQuery
JavaScript
Jenkins
Jinja2
LUIS
Lambda
LangChain
Linux
Lotus Notes
Machine Learning
Manage Secrets
Microsoft 365
Microsoft Power Platform
Microsoft Teams
Migration
Milvus
Nintex
Office Store
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Postman
Power Apps
Power Automate
PowerApps
PowerShell
Python
REST
Roles
S3
SNS
SPFX
SQL Server
SSL
SSRS
Semantic Search
Serverless
ServiceNow
SharePoint
Slack
TFS
Teams
VM
Vault
Vector Database
Windows
Windows Server
YAML
Yammer