It sounds like the delay wasn't long enough for some of the mailboxes.

From: Heaton, Joe@Wildlife [mailto:joe.hea...@wildlife.ca.gov]
Sent: Friday, December 21, 2012 4:59 PM
To: MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

The error from your script?  No, that's long gone.  Here's the error from 
Michael's version, which is the same error I was getting during my testing.  
I'm cleaning up the .csv right now, based on the results of the script run, 
which I was able to save.

Creating inbox rule for bstewart to redirect to 
bstew...@ospr.dfg.ca.gov<mailto:bstew...@ospr.dfg.ca.gov>
New-InboxRule : Cannot open mailbox /o=DFG/ou=Exchange Administrative Group (FY
DIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=HQEXCH3/cn=Microsoft System Atten
dant.
At C:\Users\admjheaton\Desktop\DFG mailbox scripts\Script-Forward-Ospr.ps1:9 ch
ar:17
+    New-InboxRule <<<<  -name "Redirect Mail" -Mailbox $_.LoginName -redirectt
o $_.EmailAddress -domainController HQDC1
    + CategoryInfo          : NotSpecified: (0:Int32) [New-InboxRule], Mailbox
   UnavailableException
    + FullyQualifiedErrorId : 2D016B11,Microsoft.Exchange.Management.Recipient
   Tasks.NewInboxRule

I'm sure it will work by now, though, it's been a few hours since the first 
run, creating the boxes.

From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net]
Sent: Friday, December 21, 2012 2:19 PM
To: MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

Can you post the script and the error?

From: Heaton, Joe@Wildlife [mailto:joe.hea...@wildlife.ca.gov]
Sent: Friday, December 21, 2012 4:13 PM
To: MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

Status Report:

Tried using Rob's script but came up with something about an empty array, so I 
must not have fully understood about the $MBX?

Changed over to Michael's script and all mailboxes are being created, but not 
all redirect rules are being successful.  My thought was to re-run the script 
with just the redirect rule part later today.  I know I'll get errors, but it 
will be easier, I think, than trying to figure out which accounts got the 
redirect rule and which didn't.

What do you guys think?


From: Rob Campbell [mailto:rob_campb...@centraltechnology.net]
Sent: Friday, December 21, 2012 7:26 AM
To: Heaton, Joseph@DFG; MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

$MBX is just an array of the imported .csv file saved in memory.

This method is essentially going through the .csv twice - first to create the 
mailboxes, then again to set the rules.  Also note that [-1] in the get-mailbox 
command.  That's looking at the last row in the .csv file, so you need that 
array saved in memory to get that last array element.

Using Michael's foreach loop, you create one mailbox, then wait to create the 
rules for that mailbox and repeat that loop for each mailbox.

This creates all the mailboxes, then goes through a wait-retry-wait  loop until 
it can do a successful get-mailbox on the last mailbox created, and then goes 
back through the .csv and creates all the rules.

From: Heaton, Joseph@DFG [mailto:jhea...@dfg.ca.gov]
Sent: Friday, December 21, 2012 9:14 AM
To: MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

Ok, so Rob's script will sleep for 2 seconds at a time until the Get-Mailbox 
command is successful, right?  What does the $MBX reference?  Do I need 
something in the .csv called that?

From: Rob Campbell [mailto:rob_campb...@centraltechnology.net]
Sent: Friday, December 21, 2012 5:24 AM
To: Heaton, Joseph@DFG; MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

Alternatively:

$mbxs = Import-Csv \Users.csv
Foreach ($MBX in $mbxs){
   Enable-Mailbox -Identity $MBX.LoginName -domainController DC1
   }

'Waiting for mailbox creation to complete'

Do {Sleep 2}
   Until (Get-Mailbox $mbxs[-1].loginname)

Foreach ($MBX in $mbxs){
   Write-Output "Creating inbox rule for $($MBX_.LoginName) to redirect to 
$($MBX.EmailAddress)"
   New-InboxRule -name "Redirect Mail" -Mailbox $MBX.LoginName -redirectto 
$MBX.EmailAddress -domainController DC1
   }


From: Michael B. Smith 
[mailto:michael@smithconscom<mailto:mich...@smithcons.com>]
Sent: Friday, December 21, 2012 6:13 AM
To: MS-Exchange Admin Issues
Subject: RE: Add a pause in a script?

If you specify the domainController on each command, it will probably work 
immediately. For example, assume the local DC is named DC1. I also illustrated 
a couple of other useful techniques. :)

Import-Csv .\Users.csv | Foreach-Object{
   Enable-Mailbox -Identity $_.LoginName -domainController DC1
   Sleep 5 ### delay for 5 seconds
   Write-Output "Creating inbox rule for $($_.LoginName) to redirect to 
$($_.EmailAddress)"
   New-InboxRule -name "Redirect Mail" -Mailbox $_.LoginName -redirectto 
$_.EmailAddress -domainController DC1
   }


From: Heaton, Joseph@DFG [mailto:jhea...@dfg.ca.gov]
Sent: Friday, December 21, 2012 12:35 AM
To: MS-Exchange Admin Issues
Subject: Add a pause in a script?

I want to create a bunch of mailboxes, then add a redirect rule to them.  I 
have my .csv file with names (LoginName) and addresses to forward to 
(EmailAddress).  Here is the script:

Import-Csv .\Users.csv | Foreach-Object{
   Enable-Mailbox -Identity $_.LoginName
   New-InboxRule -name "Redirect Mail" -Mailbox $_.LoginName -redirectto 
$_.EmailAddress
   }

The mailboxes are created fine, but then I get an error when it tries to create 
the inbox rule, saying the mailbox doesn't exist.  If I wait 5-10 minutes, 
comment out the Enable-Mailbox line, and run the script again, it works fine, 
and creates the inbox rule.  The one thing it doesn't do at that point is tell 
me what mailbox it's creating the inbox rule for.  Is there a way to have it 
echo the mailbox, then create the inbox rule, so I can go back and verify that 
they were all done?

As always, thanks for any and all help on this.


Joe Heaton

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

**************************************************************************************************
Note:
The information contained in this message may be privileged and confidential and
protected from disclosure.  If the reader of this message is not the intended
recipient, or an employee or agent responsible for delivering this message to
the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify us immediately by
replying to the message and deleting it from your computer.
**************************************************************************************************

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

**************************************************************************************************
Note:
The information contained in this message may be privileged and confidential and
protected from disclosure.  If the reader of this message is not the intended
recipient, or an employee or agent responsible for delivering this message to
the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify us immediately by
replying to the message and deleting it from your computer.
**************************************************************************************************

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

**************************************************************************************************
Note:
The information contained in this message may be privileged and confidential and
protected from disclosure.  If the reader of this message is not the intended
recipient, or an employee or agent responsible for delivering this message to
the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify us immediately by
replying to the message and deleting it from your computer.
**************************************************************************************************

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe exchangelist
**************************************************************************************************
Note: 
The information contained in this message may be privileged and confidential 
and 
protected from disclosure.  If the reader of this message is not the intended  
recipient, or an employee or agent responsible for delivering this message to  
the intended recipient, you are hereby notified that any dissemination,   
distribution or copying of this communication is strictly prohibited. If you  
have received this communication in error, please notify us immediately by  
replying to the message and deleting it from your computer. 
**************************************************************************************************

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe exchangelist

Reply via email to