Create a Basic Script in Windows PowerShell
This “Create a Basic Script in Windows PowerShell” IT Pro Challenge virtual lab will teach you how to automate system administrator tasks using the Windows PowerShell. The PowerShell is a command-line tool to view, access, and alter system settings. After completing this virtual lab, you will know how to write and run PowerShell scripts.
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. Cmdlets can be used by skilled users to automate many repetitive tasks. 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. To make the best use of the PowerShell, you will need to understand how to combine cmdlets into a PowerShell script. This virtual lab will give you valuable experience writing scripts in Windows PowerShell.
Understand the scenario: You are a system administrator for a company that has a large number of servers to administer. You have many tools available to analyze performance and generate reports of system activity; however, the reports are cumbersome to build and take quite some time to run. You need to generate the reports quickly when they are needed. To accomplish this goal, you have decided to use Windows PowerShell.
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.
Run a command to display the processes that consume the most memory:
In this step, you will learn the Get-Process cmdlet for viewing the processes running on the virtual machine and how to output the results to a file.
Write a script to display the processes that consume the most memory:
In this step, you will create a script using the Get-Process command from the previous step. You will:
- Launch the Windows PowerShell ISE.
- Create a script using the PowerShell ISE to run the Get-Process command.
- Configure the script to get the processes for a given computer and output the results to a given file.
Prompt for input:
In this step, you will modify the script to ask the user for the computer from which to retrieve processes and the output file to write to.
Create a parameterized script:
For the final step, you will edit the script again to turn the script variables into parameters.
The Windows PowerShell gives system administrators a powerful tool for automating administrative tasks. PowerShell scripts allow users to execute complex tasks easily through programmed sequences of PowerShell commands. This virtual lab will give you hands-on experience creating and executing PowerShell scripts.
In the “Create a Basic Script in Windows PowerShell” virtual lab, you will accomplish the following:
- Connect to a Windows virtual machine hosted in Azure.
- Learn the PowerShell command for listing CPU processes.
- Create a PowerShell script to automate listing CPU processes.
- Customize the script to accept user inputs.
- Parameterize the script.