Robert Martin's Blog

A site about VMware, Powershell and Exchange topics

Browsing Posts tagged Exchange 2007

The script below was written to add about 1000 user that fit a certain criteria into a group. You could use any field of Get-Mailbox to sort, and this script filters out disabled accounts. To run this script you need to load PSSnapin Exchange and Quest

$users = Get-Mailbox -ResultSize Unlimited | ?{$_.CustomAttribute1 -eq “Phoenix” -and $_.UserAccountControl -notlike “*AccountDisabled*”} | Select GUID
Foreach($user in $users)
{
    Add-qadgroupmember –Identity “CN=WirelessUsers,OU=Groups,DC=mydomain,DC=internal” –Member $user.GUID.ToString()
}

This script was written to migrate users from one domain to another and migrate the mailboxes. Save the entire script as a .ps1 file and when you run it you will need to pass it a file name that should be in same directory as script.

# Add Exchange Module if you need to
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

This function is passed the number of seconds and it displays Sleeping for 0:0:0 seconds

# Function to Wait a number of Seconds
function CountDown($waitSeconds) {
      $startTime = get-date
      $endTime = $startTime.addSeconds($waitSeconds)
      $timeSpan = new-timespan $startTime $endTime
      write-host “`nSleeping for $waitSeconds seconds…” -backgroundcolor black -foregroundcolor yellow
      while ($timeSpan -gt 0) {
            $timeSpan = new-timespan $(get-date) $endTime
            write-host “`r”.padright(40,” “) -nonewline
            write-host $([string]::Format(“`rTime Remaining: {0:d2}:{1:d2}:{2:d2}”, `
                  $timeSpan.hours, `
                  $timeSpan.minutes, `
                  $timeSpan.seconds)) `
                  -nonewline -backgroundcolor black -foregroundcolor yellow
            sleep 1
            }
write-host “”
}

 

This section of code is what I used to get a unigue log file as I was migrating many mailboxes. You can hard code the path if desired.

# Build Log file you can use anything you want here.
$a = Get-Date
$logday = $a.Day
$logmonth = $a.Month
$logYear = $a.Year
$logHour = $a.Hour
$logMinute = $a.Minute
$logdate = $logmonth.ToString() + “_” + $logday.ToString() + “_” + $logyear.ToString() + “_” + $logHour.ToString() + $logMinute.ToString()
$logfile = “c:\conversionlog_” + $logdate + “.txt”

This section starts powershell transcript

# start log
start-transcript -path $logfile

The following code is where the file is read and the values are parsed to export the mailbox from one domain to the other. You will need a csv file with DOMAINA and DOMAINB as the two columns and for my file I used the samAccount from both domains. This code does not create the new account in the new domain it just mail enables it. But you could write that into this code if you needed that functionality.

# read file name
$file = Read-Host “Type File Name (ex. Users.csv)”
# get users
$Users = import-csv $file -delimiter ‘,’ -erroraction stop
foreach ($User in $Users)
{
# Add permission for the user running script to export
Add-MailboxPermission “$($User.DOMAINA)@fqdn.olddomain” -User:‘USER TO RUN EXPORT’ -AccessRights:FullAccess
# Write to screen what we just did
Write-Host “USER NAME permission added”
# Path and Name to Export PST File
$path = “C:\PSTBackup\$($User.DOMAINA).pst”
# Export the PST from Exchange
Export-Mailbox –Identity “$($User.DOMAINA)@fqdn.olddomain” -PSTFolderPath $path -Confirm:$false
# Write to screen what we just did
Write-Host “$($User.DOMAINA) exported to C:\PSTBackup\$($User.DOMAINA).pst”
# Disable the Exchange Attributes so we can add to new domain
Disable-Mailbox “$($User.DOMAINA)@fqdn.olddomain” -DomainController “YOUR OLD DOMAIN CONTROLLER” -Confirm:$false
# Write to screen what we just did
Write-Host “$($User.DOMAIN) mailbox disabled.”
# Run a wait function to allow AD to update
Countdown 60
# Enable the new account on new domain
Enable-Mailbox -Identity “$($User.DOMAINB)@fqdn.newdomain” -Alias $User.DOMAINB -Database ‘FULL DATABASE PATH’ -Confirm:$false
# Again wait for 60 seconds for AD to update
Countdown 60
# Add permission to new mailbox to run Import
Add-MailboxPermission “$($User.DOMAINB)@fqdn.newdomain” -User:‘USER TO RUN IMPORT’ -AccessRights:FullAccess
# Again wait for 60 second for AD to update
Countdown 60
# Import the exported PST into new mailbox
Import-Mailbox -Identity “$($User.DOMAINB)@fqdn.newdomain” -PSTFolderPath $path -Confirm:$false
# Write to screen what we just did
Write-Host “$($User.DOMAINB) imported”
}

Stop the transcript for PowerShell

stop-transcript

Ok yesterday, I ran into an issue where store.exe on one of my CCR Cluster was repeatedly crashing, with no related event logs being generated in the Application Event Log.  I called MS Premier Support and after running a debugeer on store.exe the log was related to  KnowledgeBase article 959135, it was necessary to create a registry key called “Search Folder Nesting Level” in HKLM\System\CCS\Services\MSExchangeIS\ParamtersSystem and set it to a value of 500 and a registry key called “Validate Search Folder Restriction” in HKLM\System\CCS\Services\MSExchangeIS\ParametersSystem and set the value to 1

Today I received a call that messages to one of our key users was bouncing with a rather weird NDR notificiation

:#550 5.3.4 STOREDRV.Deliver: message exceeds fixed system limits. The following information should help identify the cause: “MapiExceptionTooComplex:16.18969:890F0000, ….

I moved the mailbox to another DB and got an error but the mailbox moved.

The next recommended step is to still run ISINTEG on the DB to get rid of the corrupt data.