Scenario: You want to build a custom table to include the MailboxCount and other elements of the Get-ExchangeServer command.
$exchangeservers = Get-ExchangeServer | Where AdminDisplayVersion -like "*15*" $final = @() $Exchangeservers | %{ #Put the Server Name into a Variable $server = $_.Name #Grab the Mailbox Count Per server $MBXCount = (Get-mailbox -server $_.Name).Count #Version of Exchange $AdminDisplayVersion = $_.AdminDisplayVersion Write-Host "Checking $server" #Grab the InstallPath $ExchangeInstallPath = $null $ExchangeInstallPath = Invoke-Command –Computername $server -ScriptBlock {$env:ExchangeInstallPath} -ErrorAction STOP #Build the Array $ServerObj = New-Object PSObject $ServerObj | Add-Member NoteProperty -Name "ServerName" -Value $server $ServerObj | Add-Member NoteProperty -Name "InstallPath" -Value $ExchangeInstallPath $ServerObj | Add-Member NoteProperty -Name "MBXCount" -value $MBXCount $ServerObj | Add-Member NoteProperty -Name "Version" -value $AdminDisplayVersion $Final += $ServerObj } $Final