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
.NET
AI
ALB
API
ARM
ASPM
AWS
Actions
Amazon Bedrock
Angular
Ansible
Anti-Pattern
Architecture
Automation
Azure
Azure AD
Azure CLI
Azure Container Apps
BDC
Bash
Bitbucket
Bot
CDN
CI/CD
CLI for Microsoft 365
CSOM
Citrix
Claude AI
Cloud Computing
CloudFront
CloudWatch
Cloudflare Workers
CodeWhisperer
Community
Computer Vision API
Copilot
Data Extraction
DeepSeek
DefectDojo
DevOps
DevSecOps
Distributed Systems
Docker
Docker Scout
DynamoDB
EKS
ElastiCache
Event Driven
EventBridge
External Secrets Operator
Faith
Flask
GCP
Generative AI
GitHub
GitLab
GitLeaks
GitOps
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
Identity
InfoPath
Integration
Istio
JavaScript
Jenkins
Jinja2
Kafka
Kiali
Knowledge Base
Kubernetes
LLM
LUIS
Lambda
Lambda@Edge
LangChain
Linode
Linux
Lotus Notes
MCP
MCP server
Machine Learning
Manage Secrets
Media Processing
Microservices
Microsoft 365
Microsoft Power Platform
Migration
Milvus
Model Context Protocol
NJSScan
Nintex
OIDC
Office Store
Ollama
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Pod
Postman
Power Apps
Power Automate
PowerShell
Python
RAG
REST
Redis
Roles
S3
SNS
SPFx
SQL Server
SSL
SSRS
Security
Semantic Search
Semgrep
Serverless
Service Mesh
ServiceNow
SharePoint
Slack
Software Engineering
TFS
Teams
Terraform
VM
Vault
Vector Database
Vulnerability
Windows
Windows Server
YAML
Yammer
jQuery
tfsec