X500 Powershell
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 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 the users 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
October 6th, 2011 4:43pm
It looks like there's a missing line-break that's caused by the way this is posted. May I suggest you click on the little "Insert Code Block" icon, where you'll get a nice little PowerShell editor for posting code and it'll look a lot better.
Consider replacing this:
$emails = $Temp.EmailAddresses +="X500:" + $_.LegacyExchangeDN Set-Mailbox
$temp -EmailAddresses $emails
with this:
$X500Addr = "X500:" + $_.LegacyExchangeDN
$temp.EMailAddresses += $X500Addr
$temp | Set-Mailbox
I haven't tested this, so be sure to test it yourself with a test account.
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
October 6th, 2011 7:59pm
It looks like there's a missing line-break that's caused by the way this is posted. May I suggest you click on the little "Insert Code Block" icon, where you'll get a nice little PowerShell editor for posting code and it'll look a lot better.
Consider replacing this:
$emails = $Temp.EmailAddresses +="X500:" + $_.LegacyExchangeDN Set-Mailbox
$temp -EmailAddresses $emails
with this:
$X500Addr = "X500:" + $_.LegacyExchangeDN
$temp.EMailAddresses += $X500Addr
$temp | Set-Mailbox
I haven't tested this, so be sure to test it yourself with a test account.
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
October 7th, 2011 2:51am
thank you , that worked.
Free Windows Admin Tool Kit Click here and download it now
October 8th, 2011 9:25pm