# building an array and actions

**URL:** <https://forums.powershell.org/t/building-an-array-and-actions/188>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/building-an-array-and-actions/188 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/building-an-array-and-actions/188/1 "2011-12-31T18:30:00Z")

</div>

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 databasesforeach ($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)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/building-an-array-and-actions/188/2 "2024-05-16T20:57:54Z")

</div>

Closed on May 16, 2024, 8:57pm UTC


