0
0
PowerShellscripting~20 mins

Configuration drift detection in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Configuration Drift Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Detecting drift by comparing file hashes
You have a baseline hash stored in a variable $baselineHash. Which command outputs true if the current file hash matches the baseline, indicating no drift?
PowerShell
$baselineHash = 'ABC123'
$currentHash = Get-FileHash -Path 'C:\config.txt' -Algorithm SHA256 | Select-Object -ExpandProperty Hash
ACompare-Object $currentHash $baselineHash
B$currentHash.Equals($baselineHash)
C$currentHash -ne $baselineHash
D$currentHash -eq $baselineHash
Attempts:
2 left
💡 Hint
Use the equality operator to compare strings in PowerShell.
📝 Syntax
intermediate
2:00remaining
Correct syntax for reading configuration file content
Which PowerShell command correctly reads the content of C:\config.txt into a variable $configContent for drift analysis?
A$configContent = Get-Content -Path 'C:\config.txt' -Raw
B$configContent = Read-File 'C:\config.txt'
C$configContent = Get-Content 'C:\config.txt' | Out-String
D$configContent = Read-Content -File 'C:\config.txt'
Attempts:
2 left
💡 Hint
Use the standard cmdlet to read file content as a single string.
🚀 Application
advanced
2:00remaining
Automating drift detection with scheduled task
You want to create a scheduled task that runs a PowerShell script DetectDrift.ps1 daily at 2 AM to check configuration drift. Which command correctly creates this scheduled task?
ARegister-ScheduledTask -TaskName 'DriftCheck' -Trigger (New-ScheduledTaskTrigger -Daily -At 2am) -Action (New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument '-File C:\Scripts\DetectDrift.ps1')
BNew-ScheduledTask -Name 'DriftCheck' -Daily -At 2am -ScriptPath 'C:\Scripts\DetectDrift.ps1'
Cschtasks /create /tn DriftCheck /tr 'PowerShell.exe -File C:\Scripts\DetectDrift.ps1' /sc daily /st 02:00
DSet-ScheduledTask -TaskName 'DriftCheck' -Daily -At 2am -Script 'C:\Scripts\DetectDrift.ps1'
Attempts:
2 left
💡 Hint
Use PowerShell cmdlets to register a scheduled task with trigger and action.
🔧 Debug
advanced
2:00remaining
Identify the error in this drift detection script snippet
What error will this script produce?
$baselineHash = 'ABC123'
$currentHash = Get-FileHash -Path 'C:\config.txt' -Algorithm SHA256
if ($currentHash -eq $baselineHash) { Write-Output 'No drift' } else { Write-Output 'Drift detected' }
ARuntime error because Get-FileHash requires admin privileges
BSyntaxError due to missing parentheses in the if statement
Cfalse because $currentHash is an object, not a string, causing the comparison to fail
DNo error, outputs 'No drift' or 'Drift detected' correctly
Attempts:
2 left
💡 Hint
Check the type of $currentHash and what is being compared.
🧠 Conceptual
expert
2:00remaining
Understanding configuration drift detection strategy
Which statement best describes the main goal of configuration drift detection in automation scripts?
ATo encrypt configuration files to protect sensitive data from unauthorized access.
BTo continuously monitor and identify changes in system configuration that differ from a defined baseline, enabling timely remediation.
CTo automatically update all system configurations to the latest software versions without manual checks.
DTo backup configuration files daily to prevent data loss in case of system failure.
Attempts:
2 left
💡 Hint
Think about what 'drift' means in configuration management.