Efficient Software Deployment in M365 with PowerShell
In the fast-paced world of IT, ensuring that software is deployed efficiently across your Microsoft 365 environment is vital for maintaining productivity and compliance. This PowerShell script automates the process of deploying software applications from the Microsoft Store to users within your organization. This script will: 1. Connect to the Microsoft Graph. 2. Select users or groups for deployment. 3. Deploy a specified application to the selected users. By utilizing this script, IT professionals can streamline software deployment processes, ensuring users have access to necessary applications without manual installation.
# Install the required 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 with appropriate permissions
Connect-MgGraph -Scopes 'Application.ReadWrite.All', 'User.ReadWrite.All'
# Specify the application ID and users/groups
$appId = "your-app-id" # Replace with the application ID to deploy
$users = @("[email protected]", "[email protected]") # List of users to deploy to
# Loop through each user and deploy the application
foreach ($user in $users) {
try {
New-MgUserAppRoleAssignment -UserId $user -AppRoleId $appId -ResourceId "your-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 has 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.