Exchange 2007 Powershell Get-MailboxDatabase question

Welcome Forums General PowerShell Q&A Exchange 2007 Powershell Get-MailboxDatabase question

This topic contains 2 replies, has 2 voices, and was last updated by

Ray
 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #105814
    Ray

    Participant
    Points: 1
    Rank: Member

    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

  • #105817

    Participant
    Points: 144
    Helping Hand
    Rank: Participant

    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 !!

  • #105821
    Ray

    Participant
    Points: 1
    Rank: Member

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

The topic ‘Exchange 2007 Powershell Get-MailboxDatabase question’ is closed to new replies.