new-mailbox cmdlet and log
- Hi.
I have written a script to make new mailboxes. This script is very simple, is just like this:
import-csv newusers.csv | new-mailbox
The command new-mailbox has some parameters that I haven't written above.
It works fine.
But if some of these identities already exists in Active Directory, then some red words appear in the powershell window, warning of this error.
I'd like to keep a log about all errors found by new-mailbox command. And if new users is successfully created, then I would also like to have it in this log.
Do you know how to keep a log when using new-mailbox cmdlet?
Thanks, bye,
Mig. En.
Answers
- In that case you need to format the output with just user name and the error coming up, below is for moving mailbox but you can create similar error reporting script with new-mailbox cmdlet...PowerShell Script: Move Mailboxes From Exchange 2003 to Exchange 2007
Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration
MCITP: EMA | MCSA: M | Blog: http://ExchangeShare.WordPress.com- Marked As Answer bymig.en_ Friday, November 06, 2009 5:25 PM
- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorThursday, November 05, 2009 7:28 AM
All Replies
- You can pipe the result to a log file by using
> logfile.txt
Shaun - Ok, thanks, but I need that the log file contains only the logins that have caused an error (maybe because they already exist).
If I redirect the output, then there is a lot of text and the user who has to read the log doesn't need to know about cmdlets or Exchange, this user is just an operator who runs scripts in order to make new users, remove them, and so on.
Thank you anyway,
Mig. En. - In that case you need to format the output with just user name and the error coming up, below is for moving mailbox but you can create similar error reporting script with new-mailbox cmdlet...PowerShell Script: Move Mailboxes From Exchange 2003 to Exchange 2007
Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration
MCITP: EMA | MCSA: M | Blog: http://ExchangeShare.WordPress.com- Marked As Answer bymig.en_ Friday, November 06, 2009 5:25 PM
- Proposed As Answer byXiu Zhang - MSFTMSFT, ModeratorThursday, November 05, 2009 7:28 AM
Thank you very much for your help, Amit.
I didn't know about the $error variable.
By the way, I found a little mistake at your post. It is needed a pipe in the write-output cmdlets. The right version of your script is at:
http://gallery.technet.microsoft.com/ScriptCenter/en-us/a394cb8f-3033-457a-9b7b-258014b21ceb
Thank you very much,
Mig.En.- Oh yeh, I moved/migrated my blog from BlogSpot to Wordpress and pipe was not supported character at blogspt.Thanks for pointing it out, I have corrected it... :)
Amit Tank
MVP: Exchange Server | MCTS: Microsoft Exchange Server 2010, Configuration
MCITP: EMA | MCSA: M | Blog: http://ExchangeShare.WordPress.com


