Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which loop checks its condition before each iteration?
Not quite. Try another option.
Answer: while
A while loop evaluates its condition before running each iteration.
Question 14 of 60 · Arrays · Easy
What does a PowerShell array store?
Not quite. Try another option.
Answer: An ordered collection of values
An array stores multiple values in an ordered collection that can be accessed by index.
Question 15 of 60 · Hashtables · Easy
How does a PowerShell hashtable organize its data?
Not quite. Try another option.
Answer: As key-value pairs
A hashtable associates each unique key with a corresponding value.
Question 16 of 60 · Functions · Easy
What is a PowerShell function?
Not quite. Try another option.
Answer: A named reusable block of code
A function gives a name to a block of code so it can be called whenever needed.
Question 17 of 60 · Scoping · Easy
Which scope contains variables available throughout the current PowerShell session?
Not quite. Try another option.
Answer: Global scope
Variables in the global scope are available throughout the current PowerShell session.
Question 18 of 60 · Basic error handling · Easy
Which PowerShell block handles an error produced in a try block?
Not quite. Try another option.
Answer: catch
A catch block handles a terminating error that occurs inside its associated try block.
Question 19 of 60 · Working with help · Easy
Which cmdlet displays help information about another PowerShell command?
Not quite. Try another option.
Answer: Get-Help
Get-Help displays documentation, syntax, parameters, and examples for PowerShell commands.
Question 20 of 60 · Profiles · Easy
What is the main purpose of a PowerShell profile?
Not quite. Try another option.
Answer: To customize the PowerShell environment
A PowerShell profile is a script that can configure aliases, functions, variables, and other session settings.
Question 21 of 60 · Introduction to PowerShell · Medium
A command returns several process objects. Why can PowerShell sort these results reliably by CPU usage?
Not quite. Try another option.
Answer: It passes structured objects with named properties
PowerShell commands generally output .NET objects. Commands such as Sort-Object can operate directly on properties such as CPU.
Question 22 of 60 · Console and ISE usage · Medium
You want to test a few commands interactively and inspect each result before creating a reusable script. Which environment is most directly suited to this initial task?
Not quite. Try another option.
Answer: The PowerShell console
The PowerShell console is designed for executing commands interactively and viewing their results immediately.
Question 23 of 60 · Writing scripts · Medium
A script should accept a computer name as a named parameter. Which declaration should appear near the beginning of the script?
Not quite. Try another option.
Answer: param([string]$ComputerName)
A script-level param block defines parameters that callers can supply by name or position.
Question 24 of 60 · Variables · Medium
Given $count = 5, which statement increases the value by 3 and stores the result back in $count?
Not quite. Try another option.
Answer: $count += 3
The += assignment operator adds the right-hand value to the current variable value, making $count equal to 8.
Question 25 of 60 · User input · Medium
The statement $age = Read-Host "Enter age" is used, and the user enters 21. Which expression correctly checks whether the entered age is at least 18 using numeric comparison?
Not quite. Try another option.
Answer: [int]$age -ge 18
Read-Host returns text, so casting to [int] ensures a numeric comparison with the -ge operator.
Question 26 of 60 · Comments · Medium
Which syntax correctly comments out multiple lines in a PowerShell script?
Not quite. Try another option.
Answer: <# comment lines #>
PowerShell uses <# to begin a block comment and #> to end it.
Question 27 of 60 · Cmdlets · Medium
Which command follows the standard PowerShell Verb-Noun naming convention and retrieves running processes?
Not quite. Try another option.
Answer: Get-Process
Get-Process uses the approved verb Get and the singular noun Process, following PowerShell's cmdlet naming convention.
Question 28 of 60 · Pipelines · Medium
Which command retrieves running services and returns only those whose status is Running?
Not quite. Try another option.
Answer: Get-Service | Where-Object Status -eq 'Running'
Where-Object filters pipeline objects according to a condition on their properties.
Question 29 of 60 · Operators · Medium
What is the result of the expression 5 -gt 3 -and 2 -eq 2?
Not quite. Try another option.
Answer: True
Both comparisons are true, so combining them with -and produces the Boolean value True.
Question 30 of 60 · Conditional statements (if, else, switch) · Medium
A variable $status may contain Started, Stopped, or Paused, and a different action is required for each value. Which construct is generally the clearest choice?
Not quite. Try another option.
Answer: A switch statement
A switch statement clearly maps several possible values of one expression to different actions.
Question 31 of 60 · Loops (for, foreach, while, do) · Medium
Which loop prints the numbers 1 through 5 exactly once each?
Not quite. Try another option.
Answer: for ($i = 1; $i -le 5; $i++) { $i }
The loop starts at 1, continues while $i is at most 5, and increments $i after every iteration.
Question 32 of 60 · Loops (for, foreach, while, do) · Medium
A command inside a loop must run at least once before its condition is tested. Which loop structure meets this requirement?
Not quite. Try another option.
Answer: do { ... } while ($condition)
A do...while loop evaluates its condition after executing the body, so the body always runs at least once.
Question 33 of 60 · Arrays · Medium
Given $names = @('Ana', 'Ben', 'Chen'), which expression returns Ben?
Not quite. Try another option.
Answer: $names[1]
PowerShell arrays use zero-based indexing, so the second element is at index 1.
Question 34 of 60 · Hashtables · Medium
Given $server = @{ Name = 'WEB01'; Port = 443 }, which expression changes the port value to 8443?
Not quite. Try another option.
Answer: $server['Port'] = 8443
Assigning a new value through an existing hashtable key updates that entry. Add would fail because Port already exists.
Question 35 of 60 · Functions · Medium
Which function correctly accepts a name and returns the greeting Hello, Sam when called as Get-Greeting -Name Sam?
Not quite. Try another option.
Answer: function Get-Greeting { param($Name) "Hello, $Name" }
The param block defines Name, and the double-quoted string expands $Name to the supplied argument.
Question 36 of 60 · Scoping · Medium
A script assigns $script:logPath = 'C:/Logs/app.log' inside a function. Where is this value available afterward?
Not quite. Try another option.
Answer: Throughout the current script scope
The script: scope modifier stores the variable in the current script's scope, making it available elsewhere in that script.
Question 37 of 60 · Basic error handling · Medium
You need a missing file error from Get-Content to be handled by a nearby catch block. Which statement is appropriate?
Not quite. Try another option.
Answer: Get-Content $path -ErrorAction Stop
-ErrorAction Stop converts the non-terminating error into a terminating error that try...catch can handle.
Question 38 of 60 · Working with help · Medium
Which command displays the detailed help for Get-Process, including parameter descriptions and examples?
Not quite. Try another option.
Answer: Get-Help Get-Process -Full
Get-Help with -Full displays the complete local help content, including detailed parameters and examples when available.
Question 39 of 60 · Profiles · Medium
You want a custom function to load automatically whenever you start your current PowerShell host. Where should its definition be placed?
Not quite. Try another option.
Answer: In the file referenced by $PROFILE
The profile script referenced by $PROFILE runs when the corresponding PowerShell host starts.
Question 40 of 60 · Script files · Medium
You are currently in the directory containing Report.ps1. Which command explicitly runs that script from the current directory?
Not quite. Try another option.
Answer: ./Report.ps1
PowerShell does not search the current directory for commands by default, so ./ explicitly identifies the script's location.
Question 41 of 60 · Introduction to PowerShell · Hard
A command produces process objects and then passes them through Format-Table before another command attempts to sort by the CPU property. Why can the final sort no longer reliably access the original CPU values?
Not quite. Try another option.
Answer: Format-Table converts the stream into formatting objects intended for display.
Formatting cmdlets should normally appear at the end of a pipeline. They emit formatting instructions rather than the original objects needed for further data processing.
Question 42 of 60 · Console and ISE usage · Hard
Two PowerShell ISE tabs are opened using New PowerShell Tab. The first tab executes $global:Rate = 25, but $global:Rate is then queried in the second tab. What is the expected result?
Not quite. Try another option.
Answer: The second tab has no such variable because each tab uses a separate runspace.
Each new PowerShell tab in the ISE has an independent PowerShell session and runspace. Global scope is global only within its own runspace.
Question 43 of 60 · Writing scripts · Hard
A script contains #Requires -RunAsAdministrator near the end of the file inside a branch that would never execute. The script is started by a non-administrative user. What happens?
Not quite. Try another option.
Answer: The script is rejected before execution because requirements apply globally.
#Requires directives are checked before the script runs, regardless of their location or whether normal control flow would reach them.
Question 44 of 60 · Variables · Hard
What are the final value and runtime type of $x after [int]$x = '5'; $x = '07'?
Not quite. Try another option.
Answer: The value is 7, and the type is System.Int32.
A type constraint remains attached to the variable. Later assignments are converted to System.Int32, so the string '07' becomes the integer 7.
Question 45 of 60 · User input · Hard
Given $n = Read-Host 'Number', a user enters 10. What does $n + 5 evaluate to if no explicit conversion is performed?
Not quite. Try another option.
Answer: 105, because Read-Host returns a string and + concatenates.
Read-Host returns text by default. With a string on the left side of +, PowerShell converts 5 to text and produces '105'.
Question 46 of 60 · Comments · Hard
What happens when PowerShell parses <# outer <# inner #> outer #> 'Done'?
Not quite. Try another option.
Answer: It treats the nested block as a comment and then outputs Done.
PowerShell block comments delimited by <# and #> can be nested. After the outer comment closes, the string 'Done' is emitted.
Question 47 of 60 · Cmdlets · Hard
A function named Get-Date shadows the built-in cmdlet in the current session. Which command explicitly invokes the original cmdlet?
Not quite. Try another option.
Answer: Microsoft.PowerShell.Utility\Get-Date
A module-qualified command name bypasses the shadowing function and selects Get-Date from the Microsoft.PowerShell.Utility module.
Question 48 of 60 · Pipelines · Hard
What is the result of (Write-Output -NoEnumerate (1, 2) | Measure-Object).Count?
Not quite. Try another option.
Answer: 1, because the array is emitted as one pipeline object.
Write-Output -NoEnumerate prevents the array from being unrolled into separate pipeline items, so Measure-Object receives one object.
Question 49 of 60 · Operators · Hard
In order, what values are produced by 'PowerShell' -like 'Power*', 'PowerShell' -match '^Power', and 'PowerShell' -contains 'Power'?
Not quite. Try another option.
Answer: True, True, False
-like matches wildcards and -match matches regular expressions. -contains tests whether a collection contains an equal element; it does not search within a string.
Question 50 of 60 · Conditional statements (if, else, switch) · Hard
Which branch executes for if (@()) { 'A' } elseif ($null) { 'B' } else { 'C' }?
Not quite. Try another option.
Answer: The final branch outputs C.
An empty array is false in a Boolean context, and $null is also false. Therefore, control reaches the else branch.
Question 51 of 60 · Conditional statements (if, else, switch) · Hard
What does switch -Regex ('cat') { 'a' { 'A' }; '^c' { 'C' }; default { 'D' } } output?
Not quite. Try another option.
Answer: A followed by C, because both matching clauses execute.
A PowerShell switch can execute multiple matching clauses for the same input. default runs only when no clause matches, unless control flow changes that behavior.
Question 52 of 60 · Loops (for, foreach, while, do) · Hard
What is the final value of $sum after $sum = 0; for ($i = 0; $i -lt 5; $i++) { if ($i -eq 2) { continue }; $sum += $i }?
Not quite. Try another option.
Answer: 8, because every value except 2 is added.
continue skips the rest of the current loop body but still proceeds through the for loop's iteration expression. The sum is .
Question 53 of 60 · Arrays · Hard
After $a = 1, 2; $b = ,$a, what are $b.Count and $b[0].Count?
Not quite. Try another option.
Answer: 1 and 2, respectively
The unary comma creates a one-element outer array. Its single element is the original two-element array.
Question 54 of 60 · Hashtables · Hard
What does ([ordered]@{ b = 2; a = 1 }).Keys -join ',' produce?
Not quite. Try another option.
Answer: b,a, because insertion order is preserved.
The [ordered] type accelerator creates an ordered dictionary, so enumeration of .Keys follows insertion order.
Question 55 of 60 · Functions · Hard
Consider function Show-Stage { begin { 'B' } process { "P$_" } end { 'E' } }. What is emitted by 1..3 | Show-Stage?
Not quite. Try another option.
Answer: B, P1, P2, P3, E
The begin block runs once, process runs once per pipeline object, and end runs once after all input has been processed.
Question 56 of 60 · Scoping · Hard
At script scope, the following runs: $x = 1; function Set-X { $x = 2 }; Set-X; $x. What value is output?
Not quite. Try another option.
Answer: 1, because the function assignment creates a local variable.
A function executes in a child scope. Assigning $x there creates or updates the function-local variable unless a scope modifier such as $script:x is used.
Question 57 of 60 · Basic error handling · Hard
Why might try { Get-Item 'missing.file' } catch { 'Caught' } fail to execute the catch block even though Get-Item reports an error?
Not quite. Try another option.
Answer: Get-Item emits a non-terminating error unless error action is changed.
catch responds to terminating errors. Using -ErrorAction Stop converts this non-terminating cmdlet error into one that the catch block can handle.
Question 58 of 60 · Working with help · Hard
Which command retrieves help specifically for the Filter parameter of Get-ChildItem?
Not quite. Try another option.
Answer: Get-Help Get-ChildItem -Parameter Filter
The -Parameter option of Get-Help limits the result to documentation for the named parameter.
Question 59 of 60 · Profiles · Hard
Which profile path does the automatic variable $PROFILE represent by default?
Not quite. Try another option.
Answer: The current user and current host profile
$PROFILE refers to the current-user, current-host profile. Other profile paths are available through properties such as $PROFILE.CurrentUserAllHosts.
Question 60 of 60 · Script files · Hard
A script SetValue.ps1 contains $value = 42. From an existing session, which invocation makes $value remain available in that caller's current scope after the script finishes?
Not quite. Try another option.
Answer: . ./SetValue.ps1
Dot-sourcing runs the script in the current scope, so its variables and functions remain available. The call operator & executes it in a child scope.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of CSC104 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of CSC104 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.