… not a n issue yet but you should consider using a -SearchBase the reduce the stress you put on your DC with those queries.
Where {$_.proxyaddresses -eq "SMTP:max.mustermann@max.com"}
… as the name of this property “proxyAddressES” already suggests it’s an multivalued property. So this comparison only works when there is only one proxyaddress.
if ($user.proxyaddresses -contains "*max*") {
The comparison operator -contains checks for the existence of an element in an array. And the element has to be an exact match.
And actually you’ve already checked for “*max*” when you checked for “SMTP:max.mustermann@max.com”.
What exactly do you actually want to achieve?
ASsumed you’re looking for a particular user something like this could be a starter …