I was tired of my co workers walking by my desk and commenting about all the “red” powershell errors scrolling up my screen. So instead of writing better code I used the simple command to put those errors in a text file instead of onscreen.
For something like:
Set-mailbox -identity $upn -DeliverToMailboxAndForward $False -ForwardingSMTPAddress $email 2>> errors.txt
using the 2>> errors.txt will put those errors in that txt file instead of scrolling up the screen.
Next I will try to work in some error checking and be a better coder .. but for now.. that works.