Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / PowerShell / Adding a Simple Colorful Menu to PowerShell Script

November 17, 2015 PowerShell

Adding a Simple Colorful Menu to PowerShell Script

Let’s consider an example of making a simple colored menu for PowerShell allowing a user to easily select one of the available options of the script being executed. The script provides a user with several options to choose, control the selected option and perform the further actions depending on the choice.

Let’s assume that our simple script allows a user to start or stop a certain Windows service (wuauserv).

The list of menu options offered to a user can be displayed as follows:Write-Host '1. Start Windows Update service'
Write-Host '2. Stop Windows Update service'
Write-Host '3. Exit'

After that, prompt a user to select an option by typing its number:
$selected_menu_item = Read-Host 'Select menu item'

Then, process a user choice using “switch” operator:
Switch($selected_menu_item){
1{net start wuauserv}
2{net stop wuauserv }
3{Write-Host 'Exit'; exit}
default {Write-Host 'Incorrect input' -ForegroundColor Red}
}

Run the script and check its health.

Simple menu in Powershell

Everything works well. The only thing is that the menu appearance leaves much to be desired. We would like to see something more elegant and convenient.

You can try to create a nicer menu with a colored heading, items and a frame manually but it is very time-consuming, as you will have to calculate table frame size manually depending on the length of text boxes. It is much easier to use a ready script. In Technet gallery, there is ready Create colorful PowerShell Menu Function (https://gallery.technet.microsoft.com/scriptcenter/Create-colorful-PowerShell-8689c5b2), with all necessary features. Save the function code to a file named color_menu.psm1 and import it into PoSh session:
Import-Module C:\PS\color_menu.psm1

To run the function of making a colored menu, do the following:

CreateMenu -Title "Windows Update Script" -MenuItems "Start Windows Update service","Stop Windows Update service","Exit" -TitleColor Red -LineColor Cyan -MenuItemColor Yellow

Colored menu in Powershell script

Thus, it took us about two minutes to create a nice colored menu for the PowerShell script. Both the creator and ordinary users can easily use such script in future.

0 comment
0
Facebook Twitter Google + Pinterest
previous post
How to Create Full System Image Backup in Windows 10
next post
Windows 10 Compact OS: Reducing the Disk Footprint

Related Reading

How to Sign a PowerShell Script (PS1) with...

February 25, 2021

Configuring PowerShell Script Execution Policy

February 18, 2021

Updating Group Policy Settings on Windows Domain Computers

February 16, 2021

How to Find Inactive Computers and Users in...

January 29, 2021

Checking User Logon History in Active Directory Domain...

January 22, 2021

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • Accessing USB Flash Drive from VMWare ESXi

    February 26, 2021
  • How to Sign a PowerShell Script (PS1) with a Code Signing Certificate?

    February 25, 2021
  • Change the Default Port Number (TCP/1433) for a MS SQL Server Instance

    February 24, 2021
  • How to Shadow (Remote Control) a User’s RDP session on RDS Windows Server 2016/2019?

    February 22, 2021
  • Configuring PowerShell Script Execution Policy

    February 18, 2021
  • Configuring Proxy Settings on Windows Using Group Policy Preferences

    February 17, 2021
  • Updating Group Policy Settings on Windows Domain Computers

    February 16, 2021
  • Managing Administrative Shares (Admin$, IPC$, C$, D$) in Windows 10

    February 11, 2021
  • Packet Monitor (PktMon) – Built-in Packet Sniffer in Windows 10

    February 10, 2021
  • Fixing “Winload.efi is Missing or Contains Errors” in Windows 10

    February 5, 2021

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • HP ILO Management Using PowerShell
  • How Automatically Fill Computer Description Field in Active Directory
  • Run MySQL Queries from PowerShell
  • How to Compress & Extract ZIP Archive Using PowerShell
  • How To Configure DHCP Server Using PowerShell
Footer Logo

@2014 - 2018 - Windows OS Hub. All about operating systems for sysadmins


Back To Top