Create a Menu Script
This “Create a Menu Script” IT Pro Challenge virtual lab will teach you how to use the Windows PowerShell to create a menu. You will learn how to use PowerShell scripts to create a menu that gives less-skilled users access to PowerShell functionality. After completing this virtual lab, you will be able to develop basic PowerShell menus.
Windows PowerShell is a task-based command line shell and scripting language. PowerShell is different from the normal command prompt, because PowerShell uses different commands, called cmdlets, and was designed specifically for system administrators. To be efficient as a Windows system administrator, you will need to know how to create a PowerShell script file on Windows 10 and how to write and run scripts in the Windows PowerShell.
PowerShell offers many cmdlets for system management, and several cmdlets can be strung together to execute a particular task. It is often more efficient to combine these strings of cmdlets into a single executable file, called a script. A PowerShell script is an executable piece of PowerShell code that executes several cmdlets in sequence. One application of PowerShell scripts is creating menus. These menus are useful for giving PowerShell functionality to users who may not be skilled programmers. These menus also provide an input gateway into the more complex PowerShell capabilities you’ve created.
To make the best use of the PowerShell, you will need to understand how to create PowerShell scripts. This virtual lab will give you valuable experience writing scripts in Windows PowerShell to create menus.
Understand the scenario: You are a system administrator for your company. There are several support technicians who occasionally need to obtain details about the disks and volumes on servers in your environment. They need to be able to do this remotely using Windows Powershell, but they are not very familiar with Windows PowerShell commands. You need to create a disk tools menu that can easily be used.
Understand the environment: You are using an Azure resource group that contains an Azure virtual machine.
Configure your environment:
To begin this virtual lab, you will first prepare your resources. You will:
- Sign in to the Azure portal using given credentials.
- Connect to an Azure virtual machine.
- Launch the Windows PowerShell.
Create a basic menu that contains two items:
In this step, you will create the basic outline of your menu. You will:
- Open PowerShell ISE and create a new PowerShell script.
- Add commands to the script to initialize the menu.
- Add commands to script to display menu options.
Add menu command handlers:
Next, you will continue to develop your menu by adding executable commands. You will:
- Read user input.
- Add more menu options.
- Use a switch to execute commands based on the user’s input.
Loop through the menu:
In this step, you will add a loop and an if statement to your script. These pieces of code will keep the menu open until the user chooses to exit the script.
Add Windows PowerShell remoting:
The last step of this hands-on lab involves adding remote functionality to your script. You will add an additional input to your menu for selecting the computer on which to execute the script commands.
PowerShell scripts allow users to execute complex tasks easily through programmed sequences of PowerShell commands. PowerShell scripts can be used to create menus that give less skilled users the functionality of PowerShell. Knowing how to create menus for your users is an important skill for system administrators working in the Windows environment. This virtual lab will give you real-world experience creating and executing PowerShell scripts.
In the “Create a Menu Script” virtual lab, you will accomplish the following:
- Connect to a Windows virtual machine hosted in Azure.
- Create a PowerShell script that displays a menu.
- Add options to the menu from which a user can choose a command to execute.
- Add PowerShell remoting to execute the user’s choice on remote computers.