0
0
PowerShellscripting~20 mins

PowerShell on Linux - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Linux Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
PowerShell command output on Linux
What is the output of this PowerShell command run on a typical Linux system?
Get-Process | Where-Object { $_.CPU -gt 0 } | Select-Object -First 1 -Property Name,CPU
PowerShell
Get-Process | Where-Object { $_.CPU -gt 0 } | Select-Object -First 1 -Property Name,CPU
A@{Name=systemd; CPU=0.03125}
BNo output, command fails on Linux
C@{Name=powershell; CPU=0.0}
D@{Name=code; CPU=0.015625}
Attempts:
2 left
💡 Hint
Think about common Linux processes that consume CPU and appear in Get-Process.
📝 Syntax
intermediate
1:30remaining
Correct syntax for reading a file in PowerShell on Linux
Which option correctly reads the contents of a text file named 'log.txt' in the current directory on Linux using PowerShell?
ARead-Content log.txt
Bcat log.txt | Read-File
CGet-Content ./log.txt
DGet-FileContent log.txt
Attempts:
2 left
💡 Hint
PowerShell uses a cmdlet to read file contents, similar to cat but with a different name.
🔧 Debug
advanced
2:00remaining
Fix the error in this PowerShell script on Linux
This script is intended to list all files in /tmp and output their names, but it throws an error on Linux. What is the cause?
Get-ChildItem -Path C:\tmp | ForEach-Object { $_.Name }
PowerShell
Get-ChildItem -Path C:\tmp | ForEach-Object { $_.Name }
AGet-ChildItem cannot list files on Linux.
BThe path uses Windows-style backslashes; use /tmp instead.
CForEach-Object is not supported on Linux PowerShell.
DThe script is missing a pipeline to Out-File.
Attempts:
2 left
💡 Hint
Linux uses forward slashes in paths, unlike Windows.
🚀 Application
advanced
2:30remaining
Automate service restart with PowerShell on Linux
You want to restart the 'nginx' service on a Linux system using PowerShell. Which command correctly does this?
ARestart-Process nginx
BInvoke-Expression 'sudo systemctl restart nginx'
Csystemctl restart nginx
DRestart-Service nginx
Attempts:
2 left
💡 Hint
PowerShell provides cross-platform cmdlets for service management on Linux.
🧠 Conceptual
expert
2:00remaining
Understanding PowerShell environment differences on Linux
Which statement best describes a key difference when running PowerShell scripts on Linux compared to Windows?
APowerShell on Linux uses case-sensitive file paths and supports native Linux commands.
BPowerShell on Linux cannot run native Linux commands directly.
CPowerShell on Linux uses Windows registry to store configuration settings.
DPowerShell on Linux does not support modules or scripts.
Attempts:
2 left
💡 Hint
Think about how Linux file systems differ from Windows and how PowerShell integrates with the OS.