A have some PoSH code like this (testing in PowerShell ISE):
$db = Get-opMailboxDatabase -Status | select name, `
@{l='DB_Size_GB';e={ [math]::Round(($_.DatabaseSize.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1GB),2)}},Server
$db | Sort-Object @{e="Server";Descending=$false},@{e='DB_Size_GB';Descending=$true}
Write-Host "In DC1 there are activbe DBs: $(($db | where {$_.server -like '*DC1*'}).count)" -BackgroundColor Yellow -ForegroundColor DarkRed
I expect this code will generate output where table will be first (from code $db | sort-object etc...), then will shown string (from code write-host...), i.e. output order will be the same as commands order in script. But in fact I get reverse order: string (from Write-host)) at first, then table (from db$ | sort-object).
And if I edit code like this (add formate-table):
$db | Sort-Object @{e="Server";Descending=$false},@{e='DB_Size_GB';Descending=$true} | ft
Write-Host "In DC1 there are activbe DBs: $(($db | where {$_.server -like '*DC1*'}).count)" -BackgroundColor Yellow -ForegroundColor DarkRed
I get order I expect.
Why this happens?