If you’d like to nicely format output text, you may want to use a PSCustomObject and output it as a formatted list like so:

$infos = [PSCustomObject]@{
    Success = $true
    Datum = Get-Date
    ID = 123

}

Write-Host ($infos| Format-List | Out-String) -ForegroundColor Yellow

Simply add and adjust keys and values in your hash table.

Twitter This Tip! ReTweet this Tip!

Anonymous
  • If you want something completely useless, try my Write-Rainbow function to colorize your output.

    <#
    #############################################################################
    # Func: Write-Rainbow
    # Desc: Takes otherwise boring output and adds spice to make your life better.
    #############################################################################
    #>
    function Write-Rainbow([string]$Message,[switch]$DarkColorsAllowed)
    {
    # Not black, of course.
    $Colors = "DarkBlue", "DarkGreen", "DarkCyan", "DarkRed", "DarkMagenta", "DarkYellow", "Gray", "Darkgray", "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White"
    $LightColors = "Gray", "Blue", "Green", "Cyan", "Red", "Magenta", "Yellow", "White"
    $ColorsToUse = &{ if($DarkColorsAllowed) { $Colors } else { $LightColors } }

    $Letters = $Message.ToCharArray()
    $count = $Letters.length
    $max = $ColorsToUse.length
    for ($index = 0; $index -lt $count -1; $index++) {
    $Color = Get-Random -Minimum 0 -Maximum $max
    Write-Host $Letters[$index] -NoNewline -ForegroundColor $ColorsToUse[$Color]
    }
    Write-Host $Letters[-1]
    }

    $infos = [PSCustomObject]@{
        Success = $true
        Datum = Get-Date
        ID = 123
    
    }

    Write-Rainbow ($infos| Format-List | Out-String)