Others

Fix Get-MsolUser Returning Null DomainName Property in PowerShell

Tauseeq MagsiTauseeq Magsi Oct 28, 2026 868 views

Question details

The user needs to retrieve the DomainName property for Microsoft 365 users using the Get-MsolUser PowerShell cmdlet, but the query returns a null value.

How to Fix Get-MsolUser Returning a Null DomainName Property
Product
PowerShell
Device & OS
not provided
Scenario
Running a PowerShell script to query user details and explicitly selecting UserPrincipalName, DisplayName, Licenses, and DomainName.
Observed behavior
The command successfully returns values for most selected properties, but the DomainName property is consistently null because the MSOnline user object does not expose it as a returned property.
Before you start

Ensure you have the MSOnline PowerShell module installed, and that you have connected to your service using the Connect-MsolService cmdlet with administrative privileges.

Solution 1Recommended

Extract the Domain Name from the UserPrincipalName

Use a custom calculated property in your PowerShell pipeline to extract the domain directly from the user's email address.

In the MSOnline module, DomainName is documented as a filter parameter (used to search for users), but it is not stored as an output property on the user object itself. This is expected behavior. To view the domain, you must parse it from the UserPrincipalName property.

1
Open PowerShell

Launch PowerShell as an Administrator and authenticate to your Microsoft 365 tenant by running the Connect-MsolService command.

2
Run the custom expression command

Execute the following command to split the UserPrincipalName and extract the domain: Get-MsolUser | Select-Object UserPrincipalName, DisplayName, @{Name='DomainName';Expression={($_.UserPrincipalName -split '@')[1]}}

3
Export the results (Optional)

If you need to analyze the data, append '| Export-Csv -Path C:\users.csv -NoTypeInformation' to the command, then open the resulting CSV file in your preferred spreadsheet application.

Extract the Domain Name from the UserPrincipalName
Expected Behavior: It is completely normal for the standalone DomainName property to return null when selected directly, as the object simply does not contain this attribute.
Free Microsoft Office alternative

Manage Your IT Documentation with WPS Office

While managing complex PowerShell scripts and exporting user directories, streamline your IT documentation and CSV data analysis with WPS Office. It provides a highly compatible, fast, and free alternative to Microsoft Office.

  1. 1. Download the software: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the suite: Run the downloaded installer file and follow the quick setup instructions to install WPS Office on your computer.
  3. 3. Open exported CSVs: Launch WPS Spreadsheet to seamlessly open, format, and filter the CSV files generated by your PowerShell scripts.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx, .csv).Lightweight architecture ensures fast loading times for large exported server logs and CSV files.Tabbed interface allows you to manage multiple scripts, spreadsheets, and PDF documents in a single window.Completely free to use with a familiar user interface, ensuring zero learning curve for IT professionals.
microsoft office alternative - wps office

Frequently Asked Questions

Why is DomainName listed in the Microsoft documentation if it returns null?

DomainName is documented strictly as a filter parameter allowing administrators to search for users within a specific domain (e.g., using -DomainName 'example.com'). It is not an actual property assigned to the returned user objects.

How do I filter users by domain using Get-MsolUser?

You can use the parameter directly in your initial query to restrict results. For example: Get-MsolUser -DomainName 'yourdomain.com'. This filters the user list server-side before returning the objects to PowerShell.

What if the custom split expression returns an error for some users?

If a user account has an invalid, incomplete, or missing UserPrincipalName (without an '@' symbol), the split operation may fail or return unexpected results. Ensure your Active Directory UPNs are correctly formatted.

Should I still be using the MSOnline PowerShell module?

The MSOnline module is considered legacy. Microsoft recommends migrating to the Microsoft Graph PowerShell module for modern administration, which provides more consistent property returns and improved performance.