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.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Maybe you'd like to display a fancy banner as part of a module or your profile.
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.
Where this can get tricky is with phrases. You need to escape things like spaces.
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.
Once you have this, you can make it interesting with Write-Host.
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.
There's no end to what you can do.
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.
You totally killed my afternoon! Thanks for the fun share =)
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.
It is like any other foreign language. You have to expose yourself to it and use it every day.