I want to add the $email array to the csv as an additional column. The problem is that not all of these users have mailboxes (Emailaddress) so therefore I need to delete those lines without a mailbox - any ideas how I can do this with a simple code?
To make sure I understand the properly, you want to both add a new column to the CSV, and remove any rows for users that don’t have an email address defined? If so, try this:
(Note: I haven’t tested this code because I don’t have an Exchange environment handy, but hopefully it either works as-is or helps you figure out a solution.)