0
0
PowerShellscripting~15 mins

Boolean values in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
PMC: Boolean values
📖 Scenario: You are creating a simple script to check if a user is allowed to access a system based on their status.
🎯 Goal: Build a PowerShell script that uses Boolean values to represent user access status and prints the result.
📋 What You'll Learn
Create a Boolean variable named isUserActive with the value $true.
Create a Boolean variable named hasAccessRights with the value $false.
Use a Boolean expression to check if the user is active and has access rights.
Print the result of the Boolean expression.
💡 Why This Matters
🌍 Real World
Boolean values are used in scripts to represent true/false conditions like user status, feature flags, or system states.
💼 Career
Understanding Boolean logic is essential for automation tasks, decision-making in scripts, and controlling program flow in IT and DevOps roles.
Progress0 / 4 steps
1
Create Boolean variables
Create a Boolean variable called isUserActive and set it to $true. Also create a Boolean variable called hasAccessRights and set it to $false.
PowerShell
Need a hint?

Use $true and $false to assign Boolean values in PowerShell.

2
Create access check variable
Create a Boolean variable called canAccess that is $true only if both isUserActive and hasAccessRights are $true. Use the -and operator.
PowerShell
Need a hint?

Use -and to combine two Boolean variables in PowerShell.

3
Use if statement to check access
Write an if statement that checks if canAccess is $true. Inside the if, set a variable message to 'Access granted'. Otherwise, set message to 'Access denied'.
PowerShell
Need a hint?

Use if (condition) { } else { } to choose between two messages.

4
Print the access message
Print the value of the variable message using Write-Output.
PowerShell
Need a hint?

Use Write-Output $message to print the message to the console.