Complete the code to check if the variable $name contains the letter 'a' using the -like operator.
$name = "Sarah" if ($name [1] "*a*") { Write-Output "Contains 'a'" }
The -like operator uses wildcard patterns to check if a string matches. Here, *a* means any string containing 'a'.
Complete the code to check if the variable $text matches the regex pattern for digits using the -match operator.
$text = "Order123" if ($text [1] '\d+') { Write-Output "Contains digits" }
The -match operator uses regular expressions to check patterns. Here, \d+ matches one or more digits.
Fix the error in the code to correctly check if $filename ends with '.txt' using -like.
$filename = "report.doc" if ($filename [1] "*.txt") { Write-Output "Text file" } else { Write-Output "Not a text file" }
The -like operator with the pattern *.txt checks if the string ends with '.txt'.
Fill both blanks to create a dictionary of words and their lengths, but only include words longer than 4 characters.
$words = @('apple', 'cat', 'banana', 'dog') $lengths = $words | ForEach-Object { $word = $_; @{ [1] = [2] } } | Where-Object { $_.Value -gt 4 }
We create a dictionary with keys as words ($word) and values as their lengths ($word.Length), then filter for lengths greater than 4.
Fill all three blanks to create a hashtable of uppercase words and their lengths, including only words with length greater than 3.
$words = @('tree', 'sun', 'flower', 'sky') $result = $words | ForEach-Object { $word = $_; @{ [1] = [2] } } | Where-Object { [3] }
Keys are uppercase words ($word.ToUpper()), values are lengths ($word.Length), and filter keeps words longer than 3 characters ($word.Length -gt 3).