# Exchange 2007 Powershell Get-MailboxDatabase question

**URL:** <https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080>\
**Category:** PowerShell Help\
**Created:** [August 2, 2018, 9:25am UTC](https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080 "2018-08-02T09:25:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![randomstranger](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@randomstranger](https://forums.powershell.org/u/randomstranger)\
**Post date:** [August 2, 2018, 9:25am UTC](https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080/1 "2018-08-02T09:25:58Z")

</div>

Hi everyone, so I’m attempting to learn powershell and at the same time make lives for my colleagues a little easier since Exchange is not their specialty much less PowerShell, by attempting to ease mailbox database stats collection.

I have this script which outputs a list of mailbox databases

```
Get-MailboxDatabase | Sort-Object -Property Identity | Select Identity
```

And I have this one, that takes the output from that (ServerName\StorageGroup\Database) and gets the stats

```
Get-MailboxDatabase -Identity "ServerName\StorageGroupName\DatabaseName" | Get-MailboxStatistics | Sort-Object TotalItemsSize -Descending | Select-Object DisplayName,@{name="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}} | Export-Csv mailboxsize.csv –Encoding ascii -NoTypeInformation
```

What i’m attempting to do is have them run the script which outputs all databases, asks them to choose one, then spits out the csv file.

So far i have this:

```
$GetDatabase = Get-MailboxDatabase | Sort-Object -Property Identity | Select Identity

$x = -1

$arr = @(Get-MailboxDatabase | Sort-Object -Property Identity | Select Identity )
ForEach ($Database in $GetDatabase) {$x = $x +1; Write-host $x : $Database.Identity }; $x=-1; 

Write-Host "Which Database would you like : " -NoNewline -Foregroundcolor Yellow
Read-Host

#Database Stats Output

Get-MailboxDatabase arr[0] | Get-MailboxStatistics | Sort-Object TotalItemsSize -Descending | Select-Object DisplayName,@{name="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}} | Export-Csv mailboxsize.csv –Encoding ascii -NoTypeInformation
```

I chose x = -1 to align with the array number since when I do arr[0] I get the output (ServerName\StorageGroup\Databasename) i’m looking for.  
But i can’t figure how to do 2 things:

1. Match the users’ number to the array number, so when they type 0 its sets array number accordingly
2. How to pass arr output to the second script.

I’m pretty new to this so any help would be greatly appreciated.Thanks

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 2, 2018, 11:37am UTC](https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080/2 "2018-08-02T11:37:15Z")

</div>

You should not be using Exchange 2007 anymore. It’s reached its end of support more than one year ago. Regardless of that you could make your life easier with something like this:

```
Get-MailboxDatabase |
Select-Object -Property Identity |
Sort-Object -Property Identity |
Out-GridView -Title ‘Database Selection’ -PassThru |
Get-MailboxDatabase |
Get-MailboxStatistics |
Sort-Object -Property TotalItemsSize -Descending |
Select-Object -Property DisplayName,@{name=“TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}} |
Export-Csv -Path mailboxsize.csv –Encoding UTF8 -NoTypeInformation
```
  
**!! untested - because I don’t have access to an Exchange system at the moment !!**

---

<div class="post-metadata">

**Author:** ![randomstranger](https://avatars.discourse-cdn.com/v4/letter/r/f08c70/32.png) [@randomstranger](https://forums.powershell.org/u/randomstranger)\
**Post date:** [August 2, 2018, 11:45am UTC](https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080/3 "2018-08-02T11:45:59Z")

</div>

Hi Olaf, thanks for the suggestion. will check it out.

---

<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:34pm UTC](https://forums.powershell.org/t/exchange-2007-powershell-get-mailboxdatabase-question/11080/4 "2024-05-16T20:34:38Z")

</div>


