Someone asked the question this week
“We need to get the user's list from POWER SHELL sorting by database , ProhibitsendrecieveQuota, mailboxsize & lastlogontime ( those who have not been logged on their mails for 60 days).
I hope there should be merged these two comlets "get-mailbox "and "get-mailboxstatistics".
Out put format should be as follows:
Alias, Databasename, ProhibitsendrecieveQuota, lastlogontime
Peter MailDB 100 MB 30/11/2007 “
While I might go about this another way such as writing another little gui or mod the mailbox size report it’s a useful problem to confront for people who are getting more and more comfortable with Pipelining in Exchange Management Shell but maybe not really sure how you could go about combining two or three cmdlets like I have and still get the normal output features.
The answer is relatively easy all you need to do is create your own custom collection and then write the result of your combined cmdlet queries to your custom collection and then at the end of the pipeline you can then use the normal export-csv or format-table cmds. For example here’s a script that solves the question asked and allows both outputting the result to a screen and exporting to a csv.
$mbcombCollection = @()
Get-Mailbox -ResultSize Unlimited | foreach-object{
$mbstatis = get-mailboxstatistics $_.identity
$mbcomb = "" | select Alias,Databasename,ProhibitsendrecieveQuota,lastlogontime
$pequote = "unlimited"
$dbarry = $_.Database.ToString().split("\")
if ($_.UseDatabaseQuotaDefaults -eq $true){
$dbsetting = get-Mailboxdatabase $_.database
if ($dbsetting.ProhibitSendReceiveQuota -ne "unlimited"){
$pequote = $dbsetting.ProhibitSendReceiveQuota.Value.ToMB()
}
}
else {
if ($_.ProhibitSendReceiveQuota -ne "unlimited"){
$pequote = $_.ProhibitSendReceiveQuota.Value.ToMB()
}}
$mbcomb.Alias = $_.Alias
$mbcomb.Databasename = $dbarry[2]
$mbcomb.ProhibitsendrecieveQuota = 299
$mbcomb.lastlogontime = $mbstatis.LastLogonTime
$mbcombCollection += $mbcomb
}
$mbcombCollection
$mbcombCollection | Export-Csv C:\LogonStats.csv