I am trying to use Write-Host to output data into columns. I have found a way to do this, but it is quite messy:
Firstly, I set the console size using the following function:
function fn_SetConsoleSize {
param ([int]$height, [int]$width, [string]$title)
$bheight = $height
if ($height -le 50) {
$bHeight = 51
}
$bwidth = $width
if ($width -le 150) {
$bwidth = 150
}
$pshost = Get-Host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = $bHeight
$newsize.width = $bwidth
$pswindow.buffersize = $newsize
<# Window Size #>
$newsize = $pswindow.windowsize
$newsize.height = $height
$newsize.width = $width
$pswindow.windowsize = $newsize
<# Other Console Changes #>
$pswindow.windowtitle = $title
$pswindow.foregroundcolor = "Yellow"
$pswindow.backgroundcolor = "Black"
}
Then I just set the column sizes using whitespaces:
Write-Host ( " " * 20 ) "Candidates = $($Counts[0])" -nonewline
Write-Host (" " * ( 32 - $($Counts[0]).tostring().length)) "Candidates = $($Counts[0])"
Write-Host ( " " * 20 ) "Contacts = $($Counts[1])" -nonewline
Write-Host (" " * ( 32 - $($Counts[1]).tostring().length)) "Contacts = $($Counts[1])"
This does output how I want it to, but this part of my project is going to be quite long, so I would like to simplify this quite a lot if possible.
Here is an example of the output:
