0
0
PowerShellscripting~30 mins

Logical operators (-and, -or, -not) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Logical Operators in PowerShell
📖 Scenario: You are managing a list of employees and their work statuses. You want to check who is eligible for a bonus based on their attendance and performance.
🎯 Goal: Build a PowerShell script that uses logical operators -and and -not to filter employees based on their attendance and performance.
📋 What You'll Learn
Create a dictionary called employees with employee names as keys and a nested dictionary as values containing attendance and performance scores.
Create a variable called attendance_threshold set to 80.
Use a foreach loop with variables name and info to iterate over employees.GetEnumerator().
Inside the loop, use logical operators -and and -not to check if an employee's attendance is above the threshold and performance is good.
Print the names of employees who qualify for the bonus.
💡 Why This Matters
🌍 Real World
Filtering employee data based on multiple conditions is common in HR and management tasks to decide bonuses or promotions.
💼 Career
Understanding logical operators and loops in PowerShell helps automate administrative tasks and data filtering in IT and business roles.
Progress0 / 4 steps
1
Create the employee data
Create a dictionary called employees with these exact entries: 'Alice' with attendance 90 and performance 85, 'Bob' with attendance 75 and performance 95, 'Charlie' with attendance 82 and performance 70.
PowerShell
Need a hint?

Use @{} to create nested dictionaries for each employee.

2
Set the attendance threshold
Create a variable called attendance_threshold and set it to 80.
PowerShell
Need a hint?

Just assign the number 80 to $attendance_threshold.

3
Use logical operators to find eligible employees
Use a foreach loop with variables name and info to iterate over $employees.GetEnumerator(). Inside the loop, use the logical operator -and to check if info.attendance is greater than or equal to $attendance_threshold and info.performance is greater than 80. Also, use -not to exclude employees with performance less than 75. Store the names of employees who meet these conditions in a list called eligible.
PowerShell
Need a hint?

Use foreach ($entry in $employees.GetEnumerator()) and inside the loop check conditions with -and and -not. Add qualifying names to $eligible.

4
Print the eligible employees
Write a Write-Output statement to print the list $eligible.
PowerShell
Need a hint?

Use Write-Output $eligible to show the names of employees who qualify.