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
AI
API
ARM
ASPM
AWS
AWS Comprehend
AWS Secrets Manager
Actions
Amazon Bedrock
Angular
Ansible
Automation
Azure
Azure CLI
BDC
Bash
Bible API
Bitbucket
Bot
CI/CD
CLI for Microsoft 365
CSOM
Citrix
Cloud
Cloud Computing
Cloud Watch
CloudWatch
CodeWhisperer
Computer Vision API
Copilot
Data Extraction
DefectDojo
DevOps
DevSecOps
Docker
Docker Scout
Dotnet
EKS
Elastic Transcoder
EventBridge
External Secrets Operator
Faith
GCP
GenAI
Generative AI
GitHub
GitLab
GitLeaks
GitOps
Google Analytics
Governance
Graph API
Groups
HIBP API
Hashicorp
IAM
IaC
Identity
InfoPath
Integration
Istio
JQuery
JavaScript
Jenkins
Jinja2
Kiali
Kubernetes
LUIS
Lambda
LangChain
Linode
Linux
Lotus Notes
Machine Learning
Manage Secrets
Microservices
Microsoft 365
Microsoft Power Platform
Microsoft Teams
Migration
Milvus
NJSScan
Nintex
OIDC
Office Store
Ollama
OpenAI
Performance Optimization
Permissions
Pinecone
PnP
Pod
Postman
Power Apps
Power Automate
PowerApps
PowerShell
Python
REST
Redis
Roles
S3
SNS
SPFX
SQL Server
SSL
SSRS
Security
Semantic Search
Semgrep
Serverless
Service Mesh
ServiceNow
SharePoint
Slack
TFS
Teams
Terraform
VM
Vault
Vector Database
Vulnerability
Windows
Windows Server
YAML
Yammer
tfsec