The Powershell script should deliver a clear message to the users so the users understand what’s going on. But won’t it be beautiful if Powershell can also add emojis such as 😁😊❤?
Table of Contents
Requirements
- A console that supports Unicode characters higher than the basic multilingual plane >
0xFFFF
- For a better experience, download and install Windows Terminal. However, PowerShell ISE can be used but it has some limitations on how it displays the emojis.
- Knowing the Unicode emoji you want to display, you can get it from the Unicode.org website
In this tutorial, we will use the Smiley Face emoji.
Code | Emoji picture |
U+1F600 |
The easy way – PS7+ and Windows Terminal to show Powershell emojis
Windows Terminal is a very nice console that supports Windows Powershell and tabs, each tab can be a different PowerShell version. So let’s start by opening Windows Terminal
For PowerShell to display the emojis, first remove the U+ and escape the Hex value. In other words, this can be done by using the `u
Powershell escape character.
Please note that the Unicode escape is featured in the Windows Powershell version 7. Read more about the PowerShell escape character from Microsoft Docs
The usage of `u
is straight forward, `u{Unicode Hex}
.
write-host `u{1F600}
In short, it’s very convincing to use Windows Terminal and PS7 and show emoji in one-liner of code.
Using Windows PowerShell 5.1 and ISE to display emojis
Windows Powershell version 5.1 don’t support the Unicode escape character `u
, so some small manual work should be done.
Let’s display the Smiley face emoji which holds the U+1F600 Hex value. So first of all we need to remove the U+ from the equation and only keep the Hex value, in this case, 1F600, and then converting the Hex value to Int32. After that, convert the value to the UTF-16 string.
Firstly, the code below will convert the Hex value to Integer
$EmojiIcon = [System.Convert]::toInt32("1F600",16)
Secondly, convert the Unicode point which is stored in $EmojiIcon to UTF-16 String
[System.Char]::ConvertFromUtf32($EmojiIcon)
The output will be
All the Powershell Code for 5.1 ISE
$EmojiIcon = [System.Convert]::toInt32("1F600",16)
[System.Char]::ConvertFromUtf32($EmojiIcon)
Moreover, you can add this to Write-host
or Write-output
along with other text and apply certain color formating.
$EmojiIcon = [System.Convert]::toInt32("1F600",16)
Write-Host "The Operation Completed Successfully " -NoNewline
Write-Host -ForegroundColor Green ([System.Char]::ConvertFromUtf32($EmojiIcon))
Write-Host ""
Write-Host ""
In conclusion, as you can see, ISE won’t display emojis as colorful as Windows Terminal, plus it doesn’t support the display of all emojis, so this is why the recommendation is to use Windows Terminal.
Keep in mind that Powershell Console wont display any emoji
How to show Unicode in Windows 10 PowerShell Console same as FE
OS Name Microsoft Windows 10 Enterprise Version 10.0.19042 Build 19042
File Names with Unicode partially displayed in PowerShell Console; no problem in Windows 10 File Explorer.
How to configure Powershell console to display Unicode same as Windows 10 File Explorer? w/o Admin Right.
Some info in https://social.technet.microsoft.com…rshell-console
I’ve found another way to use also emojis with other variants:
1. Paste your emoji into https://dencode.com/string
2. Take the unicode escape code.
3. Replace \u with 0x
Your emoji would be:
“$([char]0xd83d)$([char]0xde00)”