Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value from one command as parameter to another command

I am trying to figure out how to get a value from one command as a parameter to another command, and use the output of both in a single table. Specifically I am using two cmdlets, Get-Mailbox and Get-MailboxStatistics (this is against an Exchange 2010 server).

From Get-Mailbox I need the DisplayName, UseDatabaseQuotaDefaults and Database fields. Added to this, I need to get from Get-MailboxStatistics the TotalItemSize and StorageLimitStatus fields.

I can run each of these commands individually, but cannot figure out how to use the DisplayName value from Get-Mailbox fed into the Identity value for Get-MailboxStatistics command and then output the whole lot into a single table.

I was trying something along these lines:

get-mailbox | ForEach-Object {write-host $_.DisplayName, $_.UseDatabaseQuotaDefaults, $_.Database, Get-MailboxStatistics $_.SamAccountName}

Instead of actually processing the Get-MailboxStatistics as a command it just display it as text. How can I get PS to treat this as a command and not text for the write-host cmdlet?

like image 703
Peter Bako Avatar asked Oct 28 '25 05:10

Peter Bako


1 Answers

You need to use parentheses, something along these lines:

get-mailbox | ForEach-Object { Write-Host ` 
    $_.DisplayName, `
    $_.UseDatabaseQuotaDefaults, `
    $_.Database, `
    (Get-MailboxStatistics $.SamAccountName) }
#   ^------- note the parentheses ---------^
like image 184
Igor Korkhov Avatar answered Oct 29 '25 22:10

Igor Korkhov