Unit 5: PowerShell Basics and Core Concepts - Practice Quiz
1 What is PowerShell primarily used for?
2 Which PowerShell environment provides a script editor and an interactive console?
3 What is a key benefit of placing PowerShell commands in a script?
4 Which symbol begins a variable name in PowerShell?
5 Which cmdlet reads input entered by a user?
6 Which character starts a single-line comment in PowerShell?
7 Which naming pattern is commonly used for PowerShell cmdlets?
8
What does the pipeline operator | do in PowerShell?
9 Which PowerShell operator tests whether two values are equal?
10 Which statement runs a block of code only when a condition is true?
11 Which statement is useful for selecting among several possible matching values?
12 Which loop is commonly used to process every item in a collection?
13 Which loop checks its condition before each iteration?
14 What does a PowerShell array store?
15 How does a PowerShell hashtable organize its data?
16 What is a PowerShell function?
17 Which scope contains variables available throughout the current PowerShell session?
18
Which PowerShell block handles an error produced in a try block?
19 Which cmdlet displays help information about another PowerShell command?
20 What is the main purpose of a PowerShell profile?
21 A command returns several process objects. Why can PowerShell sort these results reliably by CPU usage?
22 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?
23 A script should accept a computer name as a named parameter. Which declaration should appear near the beginning of the script?
parameter $ComputerName as string
Read-Host([string]$ComputerName)
input([string]$ComputerName)
param([string]$ComputerName)
24
Given $count = 5, which statement increases the value by 3 and stores the result back in $count?
$count := 3
$count == 3
$count += 3
$count =+ 3
25
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?
$age -like 18
$age -match 18
[int]$age -ge 18
$age -contains 18
26 Which syntax correctly comments out multiple lines in a PowerShell script?
<# comment lines #>
/* comment lines */
{# comment lines #}
<!-- comment lines -->
27
Which command follows the standard PowerShell Verb-Noun naming convention and retrieves running processes?
List_Process
Get-Process
ShowProcesses
Process-Get
28
Which command retrieves running services and returns only those whose status is Running?
Get-Service | Sort-Object Status -eq 'Running'
Get-Service | Select-Object Status -eq 'Running'
Get-Service | Where-Object Status -eq 'Running'
Where-Object Status -eq 'Running' | Get-Service
29
What is the result of the expression 5 -gt 3 -and 2 -eq 2?
False
2
True
5
30
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?
while statement
switch statement
foreach statement
try statement
31 Which loop prints the numbers 1 through 5 exactly once each?
for ($i = 0; $i -le 5; $i++) { $i }
for ($i = 1; $i -le 5; $i--) { $i }
for ($i = 1; $i -lt 5; $i++) { $i }
for ($i = 1; $i -le 5; $i++) { $i }
32 A command inside a loop must run at least once before its condition is tested. Which loop structure meets this requirement?
for ($i = 0; $condition; $i++) { ... }
do { ... } while ($condition)
while ($condition) { ... }
foreach ($item in $items) { ... }
33
Given $names = @('Ana', 'Ben', 'Chen'), which expression returns Ben?
$names[-1]
$names[2]
$names[1]
$names[0]
34
Given $server = @{ Name = 'WEB01'; Port = 443 }, which expression changes the port value to 8443?
$server['Port'] = 8443
$server[8443] = 'Port'
$server.Add('Port', 8443)
$server.Port -eq 8443
35
Which function correctly accepts a name and returns the greeting Hello, Sam when called as Get-Greeting -Name Sam?
function Get-Greeting { param($Name) "Hello, $Name" }
function Get-Greeting { return 'Hello, Name' }
function Get-Greeting($Name) { 'Hello, Name' }
function Get-Greeting { Read-Host 'Hello, $Name' }
36
A script assigns $script:logPath = 'C:/Logs/app.log' inside a function. Where is this value available afterward?
37
You need a missing file error from Get-Content to be handled by a nearby catch block. Which statement is appropriate?
Get-Content $path -ErrorAction Continue
Get-Content $path -ErrorAction Stop
Get-Content $path -ErrorAction SilentlyContinue
Get-Content $path -ErrorAction Ignore
38
Which command displays the detailed help for Get-Process, including parameter descriptions and examples?
Get-Command Get-Process -Syntax
Get-Member Get-Process -View All
Show-Command Get-Process -PassThru
Get-Help Get-Process -Full
39 You want a custom function to load automatically whenever you start your current PowerShell host. Where should its definition be placed?
$HOME
Get-History
$PROFILE
$PSHOME
40
You are currently in the directory containing Report.ps1. Which command explicitly runs that script from the current directory?
./Report.ps1
Report.ps1
Import Report.ps1
Run Report.ps1
41
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?
Format-Table removes processes whose CPU property is not a string.
Format-Table permanently changes the process objects in the operating system.
Format-Table converts the stream into formatting objects intended for display.
Format-Table sorts the objects internally and locks their property order.
42
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?
25 because global scope spans the entire ISE process.
0 because undefined numeric variables default to zero.
25 only while the first tab remains selected.
43
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?
#Requires.
#Requires is never evaluated.
44
What are the final value and runtime type of $x after [int]$x = '5'; $x = '07'?
7, and the type is System.Int32.
7.0, and the type is System.Double.
07, and the type is System.String.
5, and the second assignment is ignored.
45
Given $n = Read-Host 'Number', a user enters 10. What does $n + 5 evaluate to if no explicit conversion is performed?
10, because adding an integer to a string has no effect.
105, because Read-Host returns a string and + concatenates.
15, because numeric-looking console input is inferred as an integer.
46
What happens when PowerShell parses <# outer <# inner #> outer #> 'Done'?
Done.
outer as a comment and attempts to run inner.
47
A function named Get-Date shadows the built-in cmdlet in the current session. Which command explicitly invokes the original cmdlet?
Microsoft.PowerShell.Utility\Get-Date
Cmdlet:Get-Date
global:Get-Date
Get-Date.exe
48
What is the result of (Write-Output -NoEnumerate (1, 2) | Measure-Object).Count?
2, because pipeline input always enumerates arrays automatically.
1, because the array is emitted as one pipeline object.
0, because -NoEnumerate suppresses all pipeline output.
3, because the array and both elements are counted separately.
49
In order, what values are produced by 'PowerShell' -like 'Power*', 'PowerShell' -match '^Power', and 'PowerShell' -contains 'Power'?
False, True, False
True, True, True
True, True, False
True, False, True
50
Which branch executes for if (@()) { 'A' } elseif ($null) { 'B' } else { 'C' }?
B.
A.
C.
51
What does switch -Regex ('cat') { 'a' { 'A' }; '^c' { 'C' }; default { 'D' } } output?
A followed by C, because both matching clauses execute.
A, because the first matching clause ends the switch.
A, C, and D, because every clause is evaluated.
C, because the most specific regular expression wins.
52
What is the final value of $sum after $sum = 0; for ($i = 0; $i -lt 5; $i++) { if ($i -eq 2) { continue }; $sum += $i }?
8, because every value except 2 is added.
10, because continue affects only the conditional statement.
7, because the iteration expression is skipped by continue.
6, because execution stops when $i reaches 2.
53
After $a = 1, 2; $b = ,$a, what are $b.Count and $b[0].Count?
1 and 1, respectively
2 and 1, respectively
1 and 2, respectively
2 and 2, respectively
54
What does ([ordered]@{ b = 2; a = 1 }).Keys -join ',' produce?
a=1,b=2, because entries are converted to strings.
b,a, because insertion order is preserved.
1,2, because .Keys returns associated values.
a,b, because keys are alphabetically sorted.
55
Consider function Show-Stage { begin { 'B' } process { "P$_" } end { 'E' } }. What is emitted by 1..3 | Show-Stage?
B, P1, P2, P3, E
P1, P2, P3
B, P3, E
B, P1, E, B, P2, E, B, P3, E
56
At script scope, the following runs: $x = 1; function Set-X { $x = 2 }; Set-X; $x. What value is output?
1, because the function assignment creates a local variable.
$x exists in more than one scope.
2, because child scopes always update their parent variables.
$null, because the function removes the script-scoped variable.
57
Why might try { Get-Item 'missing.file' } catch { 'Caught' } fail to execute the catch block even though Get-Item reports an error?
Get-Item writes missing-file messages directly to standard output.
Get-Item emits a non-terminating error unless error action is changed.
catch handles only syntax errors unless a type name is supplied.
try blocks cannot contain cmdlets that access the file system.
58
Which command retrieves help specifically for the Filter parameter of Get-ChildItem?
Show-Command Get-ChildItem -Help Filter
Get-ChildItem -HelpParameter Filter
Get-Help Get-ChildItem -Parameter Filter
Get-Help Filter -Command Get-ChildItem
59
Which profile path does the automatic variable $PROFILE represent by default?
60
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?
. ./SetValue.ps1
Start-Process ./SetValue.ps1
Invoke-Item ./SetValue.ps1
& ./SetValue.ps1
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →