Fix Get-MsolUser Returning Null DomainName Property in PowerShell
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.

- 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.
Ensure you have the MSOnline PowerShell module installed, and that you have connected to your service using the Connect-MsolService cmdlet with administrative privileges.
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.
Launch PowerShell as an Administrator and authenticate to your Microsoft 365 tenant by running the Connect-MsolService 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]}}
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.

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. Download the software: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install the suite: Run the downloaded installer file and follow the quick setup instructions to install WPS Office on your computer.
- 3. Open exported CSVs: Launch WPS Spreadsheet to seamlessly open, format, and filter the CSV files generated by your PowerShell scripts.

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.




