Author Posts

January 1, 2012 at 12:00 am

by turbomcp at 2012-09-20 13:00:23

Hi i have a question
i encountered some problem in exchange(i know this is not exchange related forum, the question is general)
anyway, so solve that problem i run this command:

$DATABASES = Get-MAILBOXDATABASE | Where {$_.recovery -ne "true"} to find all db's
i then use this to find the problematic moves with weird status:
foreach($db in $databases){Get-MoveRequestStatistics -MoveRequestQueue $db| Where {$_.status -eq "Completioninprogress"}}
$badusers=foreach($db in $databases){Get-MoveRequestStatistics -MoveRequestQueue $db| Where {$_.status -eq "Completioninprogress -or $_.status -eq
"inprogress" -or $_.status -eq "moving" -or $_.status -like $null}}

now for each baduser
i have these two things i need to know:
MailboxGuid>>exchange mailbox unique guid
MoveRequestQueue>>dbname

once i know these i clean it up by running
Remove-MoveRequest –MailboxGuid 617fec7c-b437-46ba-9fe9-db54e8bc4f9e -MoveRequestQueue db15

how would i go in automating this whole thing?
an array?

Thanks in advance and sorry for the amature question
(i can do it manually its not a big deal but id like to learn how to do it)

by poshoholic at 2012-09-21 07:54:51

Not an array. You're already on the right track using foreach. For the users that you identify as $badusers, do they have the mailbox GUID and the move request queue as properties on those objects? If so you can probably do something like this:
# WARNING: This is untested script. I am not set up to test this. It is provided as an example only
# Foreach non-recovery mailbox databases
foreach ($db in Get-MailboxDatabase | Where-Object {-not $_.Recovery}) {
# Foreach mailbox that is a problematic move
foreach ($badUser in Get-MoveRequestStatistics -MoveRequestQueue $db | Where-Object {(-not $_.Status) -or (@('CompletionInProgress','InProgress','Moving') -contains $_.Status)}) {
# Remove the move request
# NOTE: In this line, I have no idea if you have a MailboxGUID property on the $badUser object or not. It's just a guess. You can change the property name to the actual name if it is different.
Remove-MoveRequest -MailboxGuid $badUser.MailboxGUID -MoveRequestQueue $db
}
}

You might be able to do this more as a one-liner. That would depend on how well Get-MailboxDatabase pipelines into Get-MoveRequestStatistics, and how well Get-MoveRequestStatistics pipelines into Remove-MoveRequest.

by turbomcp at 2012-09-21 13:03:27

i think those users do have those two attributes
(ill have to re-check but im almost sure)