PowerShell is King! Find misconfigured users in AD


Today I got a call from a customer that was working on a Office 365 Project. As part of the Project they wanted to change the Exchange Email Address Policies to filter on the Company Name for each user. Only problem was that some of the users had a blank or misspelled Company name…

Luckily, someone invented PowerShell so we started by pulling a list of all Company Names by running this command:

Get-ADUser -Filter * -Properties Company | Group Company | Select Name,Count


The result was as expected… Too many company names. Misspelled Company Names and users with no company name specified at all…


To get a list of all users with a “blank” Company Name; Run the following command:

Get-ADUser -Filter * -Properties Company | Where {$_.Company -match “^$”} | Select samaccountname


The result included a lot of service accounts and other stuff where the Company Name might not be super important. But we did find +100 accounts that needs a Company Name.


Changing the company names can of course be done by PowerShell too, but in this scenario we didn’t have any luck to automate the assignment of the different company names, but the overview helped them a lot…

+Ronni Pedersen

About Author

My name is Ronni Pedersen and I'm currently working as a Cloud Architect at APENTO in Denmark. My primary focus is Enterprise Client Management solutions, based on technologies like AzureAD, Intune, EMS and System Center Configuration Manager. I'm is also a Microsoft Certified Trainer and Microsoft MVP in Enterprise Mobility.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.