The PowerShell ASCII art

cover

Write-Ascii

  • The ​​​Write-Ascii function from my PowerShell MS-Module module can draw custom text in the PowerShell console using ASCII fonts. This article’s cover was drawn by the Write-Ascii function too. The below code does the same, it writes end of line (EOL) character or emulates the Enter key.
Write-Ascii "game`nover!"
'game', 'over!' | Write-Ascii

01.write-ascii_gameover

  • The main function’s parameter is -Text. As you could see, the parameter is positional and supports pipeline.
Write-Ascii $env:USERNAME
Write-Ascii -Text "$($env:USERNAME)`n$($env:COMPUTERNAME)"
$env:USERNAME, $env:COMPUTERNAME | Write-Ascii

The fonts

  • The ASCII characters are saved in the \Ascii\Fontname module subfolder and controlled by the -Font parameter, the Intellisense Ctrl+Space is supported.
Write-Ascii $env:USERNAME
Write-Ascii $env:USERNAME AnsiShadow
Write-Ascii $env:USERNAME -Font Electronic

02.write-ascii_font

The colors

  • The function allows to select the both, the font color by -ForegroundColor parameter and the background color -BackgroundColor. You can use more short and handy -fgc and -bgc parameter aliases. The both parameters support Intellisense Ctrl+Space and all system colors are available for the choice.
Write-Ascii $env:USERNAME -BackgroundColor Yellow -ForegroundColor Blue
Write-Ascii $env:USERNAME -BackgroundColor Red
Write-Ascii $env:USERNAME -bgc White -fgc Black

03.write-ascii_color

  • If you prefer there is option to use color numbers instead of the color names. The PowerShell currently supports 16 system colors, from 0 to 15.
Write-Ascii $env:USERNAME -bgc White -fgc Black
Write-Ascii $env:USERNAME -bgc 15 -fgc 0

04.write-ascii_colornumber

  • Tip. To get all available system colors with their corresponding numbers you can use the following one liner.
[Enum]::GetValues([ConsoleColor]) | select @{N='Color'; E={$_}}, @{N='Number'; E={([ConsoleColor]$_).value__}}
  • Using the Get-Random cmdlet you can randomize the colors. Try the following examples by yourself and see the results.
Write-Ascii 'random color' -bgc (Get-Random -Min 0 -Max 15)
'random color' | Write-Ascii -bgc (Get-Random -Min 0 -Max 15)
'random', 'color' | Write-Ascii -bgc (Get-Random -Min 0 -Max 15)
'random', 'color' |% {Write-Ascii $_ -bgc (Get-Random -Min 0 -Max 15)}
  • One more trick with the colors.
[Enum]::GetValues([System.ConsoleColor]) |% { Write-Ascii $_ -fgc $_ }
0..15 |% { Write-Ascii $_ -fgc $_ }

Summary

  • Not all symbols are supported by every font Emoj. Use -Verbose switch to view unsupported characters. If you want, you can create them by yourself and add to the font directory.
Write-Ascii '~!@#$%^&*()_+{}' -Verbose
Write-Ascii '~!@#$%^&*()_+{}' -Verbose -Font Electronic

10.write-ascii_verbose

  • For more details about the function, please take a look at the content based help and examples.
Get-Alias -Definition Write-Ascii
Get-Help Write-Ascii -Full
Get-Help Write-Ascii -Examples
Get-Help Write-Ascii -Parameter Text

You might also like

New-PercentageBar – Create colored and adjustable Percentage Bar in the PowerShell
Write-Menu – Create interactive dynamic Menu in PowerShell
Start-SleepProgress – Put PowerShell scripts to sleep with Progress Bar
Write-HostHighlight – Monitor and highlight log files

One thought on “The PowerShell ASCII art

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s