PowerShell is King! Find misconfigured users in AD

0

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

SNAGHTML13b8fb8d

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

SNAGHTML13bcd7b5

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

SNAGHTML13c3806c

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.

SNAGHTML13c91773

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…

/Enjoy
+Ronni Pedersen

About Author

My name is Ronni Pedersen and I'm currently working as a Cloud Solution Architect at EG A/S 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