0
0
PowerShellscripting~30 mins

VS Code with PowerShell extension - Mini Project: Build & Apply

Choose your learning style9 modes available
VS Code with PowerShell extension
📖 Scenario: You are learning how to use Visual Studio Code (VS Code) with the PowerShell extension to write and run PowerShell scripts easily. This project will guide you through creating a simple PowerShell script, configuring a variable, writing a loop to process data, and displaying the output in the VS Code terminal.
🎯 Goal: Build a PowerShell script that stores a list of server names, sets a threshold number, filters servers based on the threshold, and prints the filtered list in the VS Code terminal.
📋 What You'll Learn
Create a list of server names with their CPU usage percentages
Add a threshold variable to filter servers by CPU usage
Use a loop or comprehension to select servers exceeding the threshold
Print the filtered server names and their CPU usage
💡 Why This Matters
🌍 Real World
System administrators often monitor server performance using scripts. This project shows how to filter and display server CPU usage data using PowerShell in VS Code.
💼 Career
Knowing how to write and run PowerShell scripts in VS Code is essential for IT professionals managing Windows servers and automating tasks.
Progress0 / 4 steps
1
Create the initial server data
Create a variable called servers that holds a dictionary with these exact entries: 'ServerA' = 45, 'ServerB' = 70, 'ServerC' = 30, 'ServerD' = 85
PowerShell
Need a hint?

Use @{} to create a dictionary in PowerShell. Separate entries with semicolons.

2
Add a CPU usage threshold
Create a variable called threshold and set it to 50
PowerShell
Need a hint?

Just assign the number 50 to a variable named threshold.

3
Filter servers exceeding the threshold
Create a variable called highUsageServers that contains only the servers from $servers where the CPU usage is greater than $threshold. Use a foreach loop with if condition to add matching servers to highUsageServers.
PowerShell
Need a hint?

Start with an empty dictionary @{}. Loop over $servers.Keys. Use if to check if usage is greater than $threshold. Add matching servers to $highUsageServers.

4
Display the filtered servers
Use a foreach loop to print each server name and its CPU usage from $highUsageServers in the format: ServerB: 70%
PowerShell
Need a hint?

Loop over $highUsageServers.Keys. Use Write-Output with an f-string style to print the server name and usage with a percent sign.