Scenario
You are using Exclaimer and you want to update the company details for a user using the Company attribute.
Resolution
NOTE: The {Company} attribute is not available in the Microsoft 365 Admin Center.
You can edit the Company attribute within the Exchange admin center, or set the value using Powershell.
Select an option below to view the related instructions:
How to set the Company attribute for a user in the Exchange GUI
To edit the value in Exchange Online:
- Visit admin.exchange.microsoft.com.
- In the menu sidebar, expand Recipients and select Mailboxes.
- Select the user's mailbox.
- Select Organization.
- In the details panel, select Manage Organization Information.
- Enter the company name in the Company field.
- Select Save.
How to set the Company attribute for a single user using PowerShell
To set the value using Powershell:
- Install the Microsoft Graph PowerShell module, if not already installed, using the following command.
Install-Module Microsoft.Graph -Scope CurrentUser
- Connect to Microsoft Graph using the following command.
Connect-MgGraph -Scopes "User.ReadWrite.All"
- Set the Company field using the following command.
Update-MgUser -UserId <username> -CompanyName "New Company Name"
For example, a typical Company field may look like the following screenshot:
How to set the Company attribute for all users matching a domain using PowerShell
Running the Script Using PowerShell ISE or Visual Studio Code
Step 1: Install PowerShell Core (if not already installed)
To download PowerShell Core:
- Go to the PowerShell GitHub releases page and download the latest stable release for your operating system.
- Follow the installation instructions provided on the GitHub page.
Step 2: Install PowerShell ISE or Visual Studio Code
To install and run Powershell or Visual Studio Code:
EITHER:
- Search for PowerShell ISE in the start menu and select to launch.
NOTE: This option is for Windows only. Powershell is included with Windows.
OR
- Download Visual Studio Code from the official website and run the installation.
- Open Visual Studio Code and open the Extensions view by selecting the square icon in the sidebar or pressing
Ctrl+Shift+X
.
- Search for PowerShell and select Install on the PowerShell extension by Microsoft.
Step 3: Install the Microsoft Graph PowerShell Module
To open PowerShell ISE or Visual Studio Code:
- Launch PowerShell ISE or open a new PowerShell terminal in Visual Studio Code.
- Type the following command and press
Enter
:Install-Module Microsoft.Graph -Scope CurrentUser
- If prompted to install the NuGet provider, type
Y
and pressEnter
.
- If asked to install from an untrusted repository, type
Y
and pressEnter
.
Step 4: Connect to Microsoft Graph
To connect to your Azure AD:
- Type the following command and press
Enter
:Connect-MgGraph -Scopes "User.ReadWrite.All"
- Enter your Azure AD admin credentials in the sign in window.
Step 5: Run the Script
To enter and run the script:
- Copy the following script:
# Define the target domain and new company name
$targetDomain = "example.com"
$newCompanyName = "New Company Name"
# Get all users
$allUsers = Get-MgUser -All
# Filter users by email domain
$filteredUsers = $allUsers | Where-Object { $_.Mail -like "*@$targetDomain" }
# Iterate over each filtered user and update the company name
foreach ($user in $filteredUsers) {
$userId = $user.Id
Write-Output "Updating company name for user: $($user.UserPrincipalName)"
Update-MgUser -UserId $userId -CompanyName $newCompanyName
}
Write-Output "Company name updated successfully for all users with domain $targetDomain." - Paste the script into a new script file in PowerShell ISE or Visual Studio Code.
- If using PowerShell ISE, select Run Script, indicated by a green Play icon, or press
F5
.
- If using Visual Studio Code, select Run, indicated by a green Play icon, or press
F5
.