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:
- Match the users’ number to the array number, so when they type 0 its sets array number accordingly
- How to pass arr output to the second script.
I’m pretty new to this so any help would be greatly appreciated.Thanks