← script library
Streamlining Microsoft 365 User Management with PowerShell
Microsoft 365 & Entra IDJanuary 9, 2025
Today, we are diving into a useful script that simplifies user management in Microsoft 365. This script allows you to retrieve a list of all users in your organization and export the details to a CSV file for further analysis.
powershell
# Install the MSOnline module if its not already installed.
Install-Module -Name MSOnline -Force -AllowClobber
# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Get all users and select relevant properties
$userList = Get-MsolUser | Select-Object DisplayName, UserPrincipalName, IsLicensed
# Export user details to a CSV file
$userList | Export-Csv -Path "C:\Users\YourUsername\Documents\M365Users.csv" -NoTypeInformation
# Disconnect from Microsoft 365
Disconnect-MsolServiceRun 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.