Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun PowerShell ASCII Art

Posted on February 14, 2020February 14, 2020

Today's post is definitely on the fun side. In fact, I apologize in advance for the afternoon you are about to blow playing with this code. Those of you of a certain age will recall dial up modems and bulletin boards. Part of the experience was visual. Board operators often displayed the name of their site in some form of ASCII Art.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

image

Maybe you'd like to display a fancy banner as part of a module or your profile.

image

Here's an easy way to turn a piece of text into ASCII art using the API offered at http://artii.herokuapp.com/.

You can use Invoke-RestMethod to  invoke the API. You need to specify a string of text and a font.  You can get a list of fonts by running this command:

invoke-restmethod https://artii.herokuapp.com/fonts_list

The font names are case-sensitive. As to what the fonts look like, well, that's where your afternoon is about to go. Not every font will produce useable results for every text sample. Things can get a little weird with numbers and symbols with some of the fonts. Again, you can use Invoke-RestMethod to run the make API, specifying the text and font.

image

Where this can get tricky is with phrases. You need to escape things like spaces.

image

You would use the escaped text in the Invoke-RestMethod call. But relax, I've made this easier with a function.

#requires -version 5.1
#ConvertTo-ASCIIArt.ps1

<#
font list at https://artii.herokuapp.com/fonts_list
font names are case-sensitive

invoke-restmethod https://artii.herokuapp.com/fonts_list

#>

Function ConvertTo-ASCIIArt {
    [cmdletbinding()]
    [alias("cart")]
    [outputtype([System.String])]
    Param(
        [Parameter(Position = 0, Mandatory, HelpMessage = "Enter a short string of text to convert", ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [string]$Text,
        [Parameter(Position = 1,HelpMessage = "Specify a font from https://artii.herokuapp.com/fonts_list. Font names are case-sensitive")]
        [ValidateNotNullOrEmpty()]
        [string]$Font = "big"
    )

    Begin {
        Write-Verbose "[$((Get-Date).TimeofDay) BEGIN] Starting $($myinvocation.mycommand)"
    } #begin

    Process {
        Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Processing $text with font $Font"
        $testEncode = [uri]::EscapeDataString($Text)
        $url = "http://artii.herokuapp.com/make?text=$testEncode&font=$Font"
        Try {
            Invoke-Restmethod -Uri $url -DisableKeepAlive -ErrorAction Stop
        }
        Catch {
            Throw $_
        }
    } #process
    End {
        Write-Verbose "[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)"
    } #end
}

l even defined an alias to make is super easy.

image

Once you have this, you can make it interesting with Write-Host.

image

Or take a look at this code:

$t = @"
  _____                       _____ _          _ _ 
 |  __ \                     / ____| |        | | |
 | |__) |____      _____ _ __ (___ | |__   ___| | |
 |  ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |
 | |  | (_) \ V  V /  __/ |  ____) | | | |  __/ | |
 |_|   \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|
                                                   
"@

for ($i=0;$i -lt $t.length;$i++) {
if ($i%2) {
 $c = "red"
}
elseif ($i%5) {
 $c = "yellow"
}
elseif ($i%7) {
 $c = "green"
}
else {
   $c = "white"
}
write-host $t[$i] -NoNewline -ForegroundColor $c
}

I created the art text at the console and copied it to the clipboard where I could paste it as a here string.

image

There's no end to what you can do.

image

So have fun. Sorry about your afternoon. And if you come up with a use case for this, I'd love to hear about it.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

3 thoughts on “Friday Fun PowerShell ASCII Art”

  1. z says:
    February 14, 2020 at 4:40 pm

    You totally killed my afternoon! Thanks for the fun share =)

  2. NoOneSpecial says:
    February 15, 2020 at 11:47 am

    I thoroughly enjoy your blog and would love to walk around, just for one day, with all of your knowledge. For some unknown reason, PowerShell does not come easy for me. I want it to, but it just doesn’t. Your writings give me hope and spur me on.

    1. Jeffery Hicks says:
      February 15, 2020 at 11:48 am

      It is like any other foreign language. You have to expose yourself to it and use it every day.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d