Managing user attributes in Microsoft 365 can be a time-consuming task, especially when you need to update multiple users. With Graph PowerShell module, you can automate this process and update user attributes in bulk using a CSV file. This article provides a step-by-step guide on how to achieve this.
Install-Module -Name Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.ReadWrite.All"
UserPrincipalName,DisplayName,JobTitle,Department,MobilePhone
user1@domain.com,John Doe,Manager,HR,1234567890
user2@domain.com,Jane Smith,Engineer,IT,0987654321
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Path to the CSV file
$csvPath = "C:\Path\To\Your\CSV\users.csv"
# Import the CSV file
$users = Import-Csv -Path $csvPath
# Loop through each user and update attributes
foreach ($user in $users) {
try {
# Prepare the update payload
$updateParams = @{
DisplayName = $user.DisplayName
JobTitle = $user.JobTitle
Department = $user.Department
MobilePhone = $user.MobilePhone
}
# Update the user attributes
Update-MgUser -UserId $user.UserPrincipalName -BodyParameter $updateParams
Write-Host "Successfully updated user: $($user.UserPrincipalName)"
}
catch {
Write-Host "Failed to update user: $($user.UserPrincipalName). Error: $_"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
The script does the following:
The script can be enhanced by doing the following:
Automating the bulk update of user attributes using the Graph PowerShell module can save a significant amount of time and effort. By leveraging a simple CSV file and a PowerShell script, you can efficiently manage user attributes across your organization.
© m365corner.com. All Rights Reserved. Design by HTML Codex