Automating Software Deployment in Microsoft 365 with PowerShell
Efficient software deployment is essential for ensuring that users have access to the applications they need to perform their jobs. This PowerShell script automates the process of deploying software packages across Microsoft 365 environments, making it easier for administrators to manage application distributions. This script will: 1. Connect to Microsoft Graph API. 2. Retrieve a list of users to whom the software will be deployed. 3. Deploy specified software applications to the selected users. By utilizing this script, IT administrators can streamline software deployment processes, ensuring all users have the necessary tools to be productive.
# Install the Microsoft.Graph module if not already installed
if (-Not (Get-Module -ListAvailable -Name Microsoft.Graph)) {
Install-Module -Name Microsoft.Graph -Scope CurrentUser -AllowClobber
}
# Connect to Microsoft Graph
Connect-MgGraph -Scopes 'Application.ReadWrite.All', 'User.ReadWrite.All'
# Specify the application ID and users to deploy to
$appId = "your-app-id" # Replace with the application ID to deploy
$users = @("[email protected]", "[email protected]") # List of users
# Loop through each user and deploy the application
foreach ($user in $users) {
try {
New-MgUserAppRoleAssignment -UserId $user -AppRoleId $appId -ResourceId "your-resource-id" # Replace with the resource ID
Write-Host "Successfully deployed application to $user."
} catch {
Write-Host "Failed to deploy application to $user. Error: $_"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Write-Host "Software deployment process completed."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Microsoft 365 & Entra ID
Automate M365 User License Assignment with PowerShell
2025-01-09Manage M365 Users with PowerShell
2025-01-09Automate Microsoft 365 User License Management with PowerShell
2025-01-09Streamlining M365 User Management with PowerShell
2025-01-09PowerShell Script to Retrieve M365 User License Info
2025-01-09Automate Microsoft 365 User Report Generation with PowerShell
2025-01-09Ready when you are.
Try ServerEngine free for 7 days.