Complete the code to check if the file 'example.txt' exists.
Test-Path [1]The Test-Path cmdlet checks if the specified path exists. You need to provide the path as a string.
Complete the code to check if the directory 'C:\Data' exists.
Test-Path [1]In PowerShell, backslashes in strings must be escaped or use single quotes to treat them literally. Using single quotes with double backslashes is correct here.
Fix the error in the code to check if 'log.txt' exists in the current directory.
if (Test-Path [1]) { Write-Output 'Exists' } else { Write-Output 'Missing' }
The path must be a string, so it needs quotes. Without quotes, PowerShell treats it as a command or variable, causing an error.
Fill both blanks to create a hashtable of files with their existence status for 'file1.txt' and 'file2.txt'.
$files = @{ 'file1' = Test-Path [1]; 'file2' = Test-Path [2] }Each Test-Path call needs the correct file path as a string to check existence.
Fill all three blanks to create a filtered list of existing '.log' files from an array.
$logs = @('app.log', 'error.log', 'readme.txt') | Where-Object { Test-Path [1] } | ForEach-Object { $_.[2] } | Where-Object { $_.[3] -eq '.log' }
The code checks if the file exists by prepending './' to the filename, then extracts the file extension to filter '.log' files using Split-Path with the Extension property.