0
0
PowerShellscripting~20 mins

Test-Path for existence checks in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Test-Path Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1: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'
ATrue
BFalse
CThrows an error
DReturns the file size
Attempts:
2 left
💡 Hint
Test-Path returns True if the path exists, otherwise False.
💻 Command Output
intermediate
1: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 Container
ATrue
BThrows an error
CFalse
DReturns an empty string
Attempts:
2 left
💡 Hint
Test-Path returns False if the directory does not exist.
📝 Syntax
advanced
2: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).
ATest-Path 'C:\data\report.csv' -Type Leaf
BTest-Path -Path 'C:\data\report.csv' -PathType Container
CTest-Path -PathType Leaf 'C:\data\report.csv'
DTest-Path -Path 'C:\data\report.csv' -PathType Leaf
Attempts:
2 left
💡 Hint
The -PathType parameter must be followed by Leaf or Container to specify file or directory.
🚀 Application
advanced
2: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?
ATest-Path 'C:\temp\file1.txt', 'C:\temp\file2.txt' | Where-Object { $_ -eq $false }
B(Test-Path 'C:\temp\file1.txt') -and (Test-Path 'C:\temp\file2.txt')
CTest-Path -Path 'C:\temp\file1.txt' -and 'C:\temp\file2.txt'
DTest-Path 'C:\temp\file1.txt' -and Test-Path 'C:\temp\file2.txt'
Attempts:
2 left
💡 Hint
Use logical operators to combine multiple Test-Path results.
🔧 Debug
expert
2: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'
ABecause Test-Path requires backslashes \ not forward slashes / in Windows paths
BBecause Test-Path cannot check files, only directories
CBecause the file extension is missing
DBecause the path string is not quoted
Attempts:
2 left
💡 Hint
Windows paths usually use backslashes. Forward slashes may cause path not found.