PowerShell Function to create colorful menus

I was preparing a PowerShell demo for System Center Universe and decided to use nested menus in order to easily browse between different demo sections. This is how it looks like in action.

Couple of simple loops checks for the inputs and redirects you to the next level/menu.

Creating loops and logic was simple but drawing menus and lines was not easy as I expected. This is what I came up after couple of hours:

Write-Host “╔════════════════════════════════════════════════════════════════╗”-ForegroundColor Magenta
Write-Host “║” -f Magenta -nonewline;Write-Host “UCP Director – API Call – PowerShell Demo Script 1.0” -f Green -nonewline;Write-host “`0`0`0`0`0`0`0`0`0`0`0`0║” -ForegroundColor Magenta
Write-Host “╠════════════════════════════════════════════════════════════════╣”-ForegroundColor Magenta
Write-Host “║” -f Magenta -NoNewline;Write-Host “Please select the admin task you require:`0`0`0`0`0`0`0`0`0`0” -Fore Cyan -NoNewline;Write-host “`0`0`0`0`0`0`0`0`0`0`0`0`0║” -ForegroundColor Magenta
Write-Host “║`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0║” -f Magenta
Write-Host “║” -f Magenta -NoNewline;Write-Host “`t1. Provisioning” -f Yellow -NoNewline;write-host “`t`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0║” -Fore Magenta
Write-Host “║” -f Magenta -NoNewline;Write-Host “`t2. Monitoring” -f Yellow -NoNewline;write-host “`t`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0║” -Fore Magenta
Write-Host “╚════════════════════════════════════════════════════════════════╝`n”-ForegroundColor Magenta

Pretty ugly right? This is why I decided to create a consistent function so that everytime when I want to create a PowerShell menu I can use it.

Hopefully my Basel to London fligth delayed for 2 hours yesterday (!) and I had enough time to code it in airport.

Here is the function on Technet gallery:


Usage is quite simple and in couple of seconds you can have menus like below:



Leave a Reply

Your email address will not be published. Required fields are marked *

+ 1 = 9