Complete the code to catch errors and prevent script failure.
try { Get-Item 'C:\nonexistentfile.txt' } catch { Write-Host [1] }
The catch block handles the error and prints a message, so the script does not stop.
Complete the code to ignore errors and continue script execution.
Get-Content 'C:\missingfile.txt' -ErrorAction [1]
The -ErrorAction SilentlyContinue option tells PowerShell to ignore errors and keep running.
Fix the error in the code to handle exceptions properly.
try { Remove-Item 'C:\protectedfile.txt' } catch [1] { Write-Host 'Cannot delete file.' }
The catch block needs an exception type in square brackets to catch specific errors.
Fill both blanks to create a try-catch block that logs errors and continues.
try { [1] 'C:\file.txt' -ErrorAction Stop } catch [Exception] { [2] 'Error logged, continuing script.' }
Get-Content reads the file, and Write-Host shows the error message so the script continues.
Fill all three blanks to handle errors and assign a default value.
$content = try { [1] 'C:\data.txt' -ErrorAction Stop } catch { [2] = 'Default content' [3] }
The try block reads the file. On error, the catch assigns a default string to $content and prints a message.