Semperfi4000
 New Member Posts:6

 |
| 06 Oct 2011 12:28 PM |
|
Can anyone take a look at my script, everytime I run it, it will randomly take out all email addresses from a user(s).. I am reading from a file It's taking the User mailbox (not contacts) X500 record from Domain A, and placing setting it Domain B new Email mailbox. I've noticed that, the mailboxes that do get hit, it clears all of all email accounts, and the account is not Email Policy Enabled...
Name,legacyExchangeDN User1,/O=Technologies/OU=users/cn=Recipients/cn=User1 User2,/O=Technologies/OU=users/cn=Recipients/cn=User2 User3,/O=Technologies/OU=users/cn=Recipients/cn=User3
import-csv C:\Migration\MBX.csv | foreach { $temp = Get-Mailbox -identity $_.Name
if ($temp -ne $null) {
Write-Host $_.Name -foregroundcolor Yellow -backgroundcolor Blue -nonewline; Write-Host " X500 MBX" -nonewline; Write-Host " BLUE" -foregroundcolor Yellow -backgroundcolor Blue -nonewline;
Write-Host " User imported into MBX" Write-output $temp "X500 MBX User imported into MBX" | out-file -append $Log_MBXExists
}
elseif ($temp -eq $null) { #The user -DOES NOT EXIST-s in the MBX
Write-Host $_.Name -foregroundcolor black -backgroundcolor Yellow -nonewline; Write-Host " X500 MBX" -nonewline; Write-Host " YELLOW" -foregroundcolor black -backgroundcolor Yellow -nonewline;
Write-Host " Already Exists or MBX for MBX Does Not Exist" Write-output $_.Name "X500 MBX -DOES NOT EXIST- in the MBX list" | out-file -append $Log_MBXNoExists
}
$emails = $Temp.EmailAddresses +="X500:" + $_.LegacyExchangeDN Set-Mailbox $temp -EmailAddresses $emails } 2>C:\Migration\Logs\Logfile-MBX.txt
Thank you |
|
|
|
|
Presence
 New Member Posts:94

 |
| 06 Oct 2011 12:49 PM |
|
just initial thoughts... it probably doesn't like the lines $emails = $Temp.EmailAddresses +="X500:" + $_.LegacyExchangeDN Set-Mailbox $temp -EmailAddresses $emails } 2>C:\Migration\Logs\Logfile-MBX.txt why don't you try breaking that up a little bit... $emails = $Temp.EmailAddresses $emails += "X500:" + $_.LegacyExchangeDN Set-mailbox -identity $temp.alias -EmailAddresses $emails } Pres
|
|
|
|
|
Marco Shaw
 Veteran Member Posts:1684

 |
| 06 Oct 2011 01:02 PM |
|
I'm suspecting that those last few lines are just a copy and paste error, because they wouldn't/shouldn't work as is. I suspect that your variable is simply getting set to $null in some cases. Set-Mailbox will completely overwrite some settings, so if you say $emails is $null, maybe even due to a code error, everything will get wiped out. Not sure I'll have time to look at this in detail... |
|
|
|
|
Presence
 New Member Posts:94

 |
| 06 Oct 2011 01:07 PM |
|
another thing to consider... your commands at the bottom occur outside the scope of your if and elseif statements... so regardless of whether or not it can't find a user.. it is still going to preform those commands... if you take those brackets out, the script looks like this.. import-csv C:\Migration\MBX.csv | foreach { $temp = Get-Mailbox -identity $_.Name $emails = $Temp.EmailAddresses +="X500:" + $_.LegacyExchangeDN Set-Mailbox $temp -EmailAddresses $emails } 2>C:\Migration\Logs\Logfile-MBX.txt Pres, Semper Fi, Devil Dog!
|
|
|
|
|
Semperfi4000
 New Member Posts:6

 |
| 08 Oct 2011 05:22 PM |
|
LOL Semper Fi!! Thank you so much !! your sugguestion worked.. |
|
|
|
|