Complete the code to catch a terminating error using Try-Catch.
try { Get-Item 'C:\nonexistentfile.txt' -ErrorAction Stop } catch [[1]] { Write-Host 'Error caught' }
The catch block catches terminating errors by specifying Exception.
Complete the code to continue execution after a non-terminating error.
Get-Item 'C:\nonexistentfile.txt' -ErrorAction [1]
The -ErrorAction SilentlyContinue parameter suppresses non-terminating errors and continues execution silently.
Fix the error in the Try-Catch block to handle terminating errors properly.
try { Get-Item 'C:\nonexistentfile.txt' -ErrorAction [1] } catch { Write-Host 'Caught error' }
To make an error terminating and catch it, use -ErrorAction Stop.
Fill both blanks to create a hashtable of files with size greater than 1MB.
$files = Get-ChildItem | Where-Object { $_.Length [1] 1MB } | ForEach-Object { @{ Name = $_.Name; Size = $_.Length [2] 1MB } }The code filters files larger than 1MB using > and converts size to MB by dividing by 1MB.
Fill all three blanks to create a dictionary of file names and sizes for files larger than 500KB.
$result = @{
[1] = Get-ChildItem | Where-Object { $_.Length [2] 500KB } | ForEach-Object { $_.Name }
[3] = Get-ChildItem | Where-Object { $_.Length [2] 500KB } | ForEach-Object { $_.Length }
}The dictionary keys are Files and Size. The filter uses > to select files larger than 500KB.