This repository contains a PowerShell script that automates the process of updating user properties in Microsoft Entra ID (formerly Azure Active Directory) using the Microsoft Graph PowerShell SDK. It handles updating job titles, departments, display names, and manager assignments, along with comprehensive logging and error handling.
⚠️ Note: This script replaces older implementations using the now-deprecatedAzureADmodule. It fully supports the modernMicrosoft.GraphSDK.
- Bulk User Updates: Efficiently updates job title, department, and display name for users.
- Manager Assignment: Automatically assigns managers to users based on UPN.
- Retry Logic: Built-in retry mechanism for transient Azure AD failures.
- Logging: Detailed logs for both successful updates and errors.
To use this script, you need the following:
- PowerShell 5.1 or later.
- Microsoft Graph PowerShell SDK installed:
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
- Administrative access to Microsoft Entra ID.
- Admin consent to the following Graph API scopes:
User.ReadWrite.All,Group.ReadWrite.All
-
Clone the repository:
git clone https://github.com/uceworld/azure-ad-management-script.git
-
Prepare Your CSV File Use the sample CSV file (
users.csv) in the repository to format your data. -
On the first section of the script, replace
C:\path\to\with the actual path to your users csv file. Foruser_update_log.txtanduser_update_error_log.txt, choose a preferred path to replace theirC:\path\to\, your preferred will determine where the logFile and erorrLogFile would be created.# Path to the CSV file and log files $csvPath = "C:\path\to\users.csv" $logFilePath = "C:\path\to\user_update_log.txt" $errorLogFilePath = "C:\path\to\user_update_error_log.txt"
-
Run the script:
.\Update-AzureADUsers.ps1 -
Review the Logs: After execution, logs will be saved to
user_update_log.txtanduser_update_error_log.txtin your specified directory.
The CSV file should be structured as follows:
UserPrincipalName,JobTitle,Department,DisplayName,ManagerUPN
johndoe@company.com,Engineer,Engineering,John Doe,janedoe@company.com
janedoe@company.com,Manager,Operations,Jane Doe,johndoe@company.com- The script includes retry logic for up to 3 attempts in case of transient issues.
- Errors encountered during execution are logged in the error log file for review.
This script modernizes the approach by replacing deprecated AzureAD cmdlets with Microsoft.Graph equivalents:
| AzureAD Cmdlet | Microsoft Graph Equivalent |
|---|---|
Connect-AzureAD |
Connect-MgGraph |
Get-AzureADUser |
Get-MgUser |
Set-AzureADUser |
Update-MgUser |
Set-AzureADUserManager |
Set-MgUserManagerByRef |
ℹ️ For more details, refer to the Upgrade from Azure AD PowerShell to Microsoft Graph PowerShell documentation.
Contributions are welcome! Please see the Contributing Guidelines for more information.
This project is licensed under the MIT License. See the LICENSE file for details.