Listing all custom attributes in Office 365

While investigating a potential issue with one of our products, the question of whether any object within our AD/Azure AD has any of the customattributeXX populated popped up. Now, listing these for a given user/mailbox or a set of users is straightforward enough, but since we’re talking about a set of 15 attributes, each of which can potentially have a non-null value, and we want to cover all the relevant objects in the company, I was looking for a “quick” solution.

Well, coming up with one took an embarrassingly long time, but at the end I did manage to do what I want with a simple one-liner. At first, I tried various iterations of filtering and where-object clauses, none of which helped much. Then, I remembered the good old “hidden” PSObject object, which basically holds all the output information. More specifically, we can expand its Properties property (OK, these are getting annoying, but are not intended), then use a filter against both the Name of a given property, and its Value. This in turn gives us the ability to check any properties that match the “customattribute” string, while at the same time also checking if any of the attributes has an actual non-null value. Since we don’t care about which specific attribute has a value, as long as one of them has it, we can afford somewhat relaxed syntax.

Without further ado, one can use the cmdlet below to get a list of all the mailboxes within the organization, for which at least one of the CustomattributeXX has a non-null value.

Get-Mailbox -ResultSize Unlimited | ? {$_.PSObject.Properties | ? {$_.Name -like "CustomAttribute*" -and $_.Value} }

Since other objects can also make use of said attributes, an alternative approach would be to use the Get-Recipient cmdlet instead:

Get-Recipient -ResultSize Unlimited | ? {$_.PSObject.Properties | ? {$_.Name -like "CustomAttribute*" -and $_.Value} }

Get-User unfortunately does not expose the custom attributes, so you cannot use it for this purpose.

And in case you care also about the ExtensionCustomAttributeX attributes/values, you can use the following:

Get-Mailbox | ? {$_.PSObject.Properties | ? {$_.Name -like "*CustomAttribute*" -and $_.Value} }

or if you want to only list the extension ones:

Get-Mailbox | ? {$_.PSObject.Properties | ? {$_.Name -like "ExtensionCustomAttribute*" -and $_.Value} }

That’s it for today’s tip 🙂

1 thought on “Listing all custom attributes in Office 365

Leave a Reply

Your email address will not be published. Required fields are marked *

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