Challenge - 5 Problems
Test-Path Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this Test-Path command?
Given the following PowerShell command, what will be the output if the file C:\temp\file.txt exists?
PowerShell
Test-Path -Path 'C:\temp\file.txt'Attempts:
2 left
💡 Hint
Test-Path returns True if the path exists, otherwise False.
✗ Incorrect
Test-Path checks if the specified path exists. If the file exists, it returns True; if not, False.
💻 Command Output
intermediate1:30remaining
What does this command output if the directory does not exist?
What will be the output of this command if the directory C:\logs does NOT exist?
PowerShell
Test-Path -Path 'C:\logs' -PathType ContainerAttempts:
2 left
💡 Hint
Test-Path returns False if the directory does not exist.
✗ Incorrect
The -PathType Container parameter checks specifically for directories. If the directory does not exist, the command returns False.
📝 Syntax
advanced2:00remaining
Which option correctly checks if a file exists and is a leaf (file)?
Select the correct PowerShell command to check if C:\data\report.csv exists and is a file (not a directory).
Attempts:
2 left
💡 Hint
The -PathType parameter must be followed by Leaf or Container to specify file or directory.
✗ Incorrect
Option D uses the correct syntax: -PathType Leaf checks if the path is a file. Other options have syntax errors or wrong parameters.
🚀 Application
advanced2:00remaining
How to check multiple paths existence in one command?
You want to check if both C:\temp\file1.txt and C:\temp\file2.txt exist. Which command returns True only if both exist?
Attempts:
2 left
💡 Hint
Use logical operators to combine multiple Test-Path results.
✗ Incorrect
Option B correctly uses two Test-Path calls combined with -and to ensure both paths exist. Other options are invalid syntax or incorrect logic.
🔧 Debug
expert2:30remaining
Why does this Test-Path command always return False?
Consider this command: Test-Path -Path 'C:/temp/file.txt'. Why might it always return False even if the file exists?
PowerShell
Test-Path -Path 'C:/temp/file.txt'Attempts:
2 left
💡 Hint
Windows paths usually use backslashes. Forward slashes may cause path not found.
✗ Incorrect
Test-Path on Windows expects backslashes \ in paths. Using forward slashes / causes it to look for a wrong path, returning False.