Create a Module
Learn On Demand
Learn On Demand Pro Series

Time
45 minutes
Difficulty
Beginner

Knowing how to use Windows PowerShell is an important skill for efficient systems administrators to master. This IT Pro Challenge virtual lab will teach you how to create PowerShell functions and modules to automate repetitive tasks that must be executed often. After completing this lab, you will feel confident in creating modules in PowerShell.

Start your free 3-day trial and become one of the 3 million Cybersecurity and IT professionals advancing their career goals

Sign up with
Or

Already have an account? Sign In »

Overview

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 module on Windows 10 and how to write and run modules 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 module. A PowerShell module is an executable piece of PowerShell code that executes several cmdlets in sequence. Modules are particularly useful for sequences of commands that need to be run often, automating many of a system administrators’ daily tasks.

To make the best of PowerShell, you will need to know how to write a PowerShell script module. This virtual lab will teach you how to create a PowerShell module easily.

Understand the scenario: Lately, some of your servers have been rebooting unexpectedly due to updates or potential problems. In order to determine which servers have rebooted recently, you need to build a tool that will display the amount of time that a system has been running since its last reboot.

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 (VM).
  • Launch the Windows PowerShell.

Create a Get-UpTime function:

The first step towards creating your module is creating a function for finding the time since last the boot for a given VM. You will:

  • Create a function that executes the Get-UpTime cmdlet.
  • Create a loop to execute Get-UpTime for a list of VMs.
  • Create a custom output for the module that displays the time since last boot.

Create a Module:

In this step, you build a module that uses your function from the previous step. You will save the function to a script module and test the module for certain inputs.

Create a Custom Help:

In this step, you will add a help command to your module to show a user the module’s options. You will add a comment-based help block that gives the user options for running your module.

Summary:

PowerShell modules allow users to execute complex tasks easily through programmed sequences of PowerShell commands. PowerShell modules can be used to create custom commands that can be executed in PowerShell. Knowing how to create modules will help you automate many of the daily tasks required for systems administrators, saving time and energy. This virtual lab will give you real-world experience creating and executing PowerShell modules.

In the “Create a Module” virtual lab, you will accomplish the following:

  • Connect to a Windows virtual machine hosted in Azure.
  • Create a PowerShell function using the Get-UpTime cmdlet.
  • Create a PowerShell module using your new function.
  • Add a custom help feature to your module.