header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
X500
Last Post 08 Oct 2011 05:22 PM by Semperfi4000. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Semperfi4000User is Offline
New Member
New Member
Posts:6
Avatar

--
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
    PresenceUser is Offline
    New Member
    New Member
    Posts:94
    Avatar

    --
    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 ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    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...
    PresenceUser is Offline
    New Member
    New Member
    Posts:94
    Avatar

    --
    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!

    Semperfi4000User is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    08 Oct 2011 05:22 PM
    LOL Semper Fi!!   Thank you so much !!  your sugguestion worked..
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer