Unit 5: PowerShell Basics and Core Concepts - Practice Quiz

CSC104 — It Fundamentals 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is PowerShell primarily used for?

Introduction to PowerShell Easy
A. Spreadsheet creation and data entry
B. Image editing and graphic design
C. Task automation and system administration
D. Video playback and media streaming

2 Which PowerShell environment provides a script editor and an interactive console?

Console and ISE usage Easy
A. PowerShell ISE
B. Task Manager
C. File Explorer
D. Registry Editor

3 What is a key benefit of placing PowerShell commands in a script?

Writing scripts Easy
A. The commands can be saved and reused
B. The commands always run as administrator
C. The commands become operating system files
D. The commands no longer need parameters

4 Which symbol begins a variable name in PowerShell?

Variables Easy
A. @
B. $
C. %
D. #

5 Which cmdlet reads input entered by a user?

User input Easy
A. Get-Host
B. Start-Host
C. Read-Host
D. Write-Host

6 Which character starts a single-line comment in PowerShell?

Comments Easy
A. !
B. #
C. &
D. $

7 Which naming pattern is commonly used for PowerShell cmdlets?

Cmdlets Easy
A. Verb-Noun
B. Verb_Object
C. Object.Command
D. Noun-Verb

8 What does the pipeline operator | do in PowerShell?

Pipelines Easy
A. Saves output in a script file
B. Passes output to the next command
C. Repeats the previous command
D. Displays output in a new window

9 Which PowerShell operator tests whether two values are equal?

Operators Easy
A. -lt
B. -eq
C. -ne
D. -gt

10 Which statement runs a block of code only when a condition is true?

Conditional statements (if, else, switch) Easy
A. if
B. for
C. return
D. function

11 Which statement is useful for selecting among several possible matching values?

Conditional statements (if, else, switch) Easy
A. switch
B. while
C. foreach
D. param

12 Which loop is commonly used to process every item in a collection?

Loops (for, foreach, while, do) Easy
A. switch
B. try
C. foreach
D. if

13 Which loop checks its condition before each iteration?

Loops (for, foreach, while, do) Easy
A. catch
B. switch
C. while
D. function

14 What does a PowerShell array store?

Arrays Easy
A. A list of parameter definitions
B. A single fixed command name
C. A reusable block of commands
D. An ordered collection of values

15 How does a PowerShell hashtable organize its data?

Hashtables Easy
A. As numbered script lines
B. As pipeline output streams
C. As nested command blocks
D. As key-value pairs

16 What is a PowerShell function?

Functions Easy
A. A setting stored in a profile
B. A temporary interactive console
C. A named reusable block of code
D. A collection of key-value pairs

17 Which scope contains variables available throughout the current PowerShell session?

Scoping Easy
A. Private scope
B. Script scope
C. Global scope
D. Local scope

18 Which PowerShell block handles an error produced in a try block?

Basic error handling Easy
A. switch
B. foreach
C. begin
D. catch

19 Which cmdlet displays help information about another PowerShell command?

Working with help Easy
A. Show-Output
B. Get-Command
C. Read-Host
D. Get-Help

20 What is the main purpose of a PowerShell profile?

Profiles Easy
A. To replace every PowerShell script file
B. To install the Windows operating system
C. To customize the PowerShell environment
D. To store all command output permanently

21 A command returns several process objects. Why can PowerShell sort these results reliably by CPU usage?

Introduction to PowerShell Medium
A. It parses the displayed text into columns
B. It passes structured objects with named properties
C. It converts every result into a CSV row
D. It stores every result in a global variable

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?

Console and ISE usage Medium
A. The PowerShell console
B. The Registry Editor
C. The Windows Task Scheduler
D. The Services management console

23 A script should accept a computer name as a named parameter. Which declaration should appear near the beginning of the script?

Writing scripts Medium
A. parameter $ComputerName as string
B. Read-Host([string]$ComputerName)
C. input([string]$ComputerName)
D. param([string]$ComputerName)

24 Given $count = 5, which statement increases the value by 3 and stores the result back in $count?

Variables Medium
A. $count := 3
B. $count == 3
C. $count += 3
D. $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?

User input Medium
A. $age -like 18
B. $age -match 18
C. [int]$age -ge 18
D. $age -contains 18

26 Which syntax correctly comments out multiple lines in a PowerShell script?

Comments Medium
A. <# comment lines #>
B. /* comment lines */
C. {# comment lines #}
D. <!-- comment lines -->

27 Which command follows the standard PowerShell Verb-Noun naming convention and retrieves running processes?

Cmdlets Medium
A. List_Process
B. Get-Process
C. ShowProcesses
D. Process-Get

28 Which command retrieves running services and returns only those whose status is Running?

Pipelines Medium
A. Get-Service | Sort-Object Status -eq 'Running'
B. Get-Service | Select-Object Status -eq 'Running'
C. Get-Service | Where-Object Status -eq 'Running'
D. Where-Object Status -eq 'Running' | Get-Service

29 What is the result of the expression 5 -gt 3 -and 2 -eq 2?

Operators Medium
A. False
B. 2
C. True
D. 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?

Conditional statements (if, else, switch) Medium
A. A while statement
B. A switch statement
C. A foreach statement
D. A try statement

31 Which loop prints the numbers 1 through 5 exactly once each?

Loops (for, foreach, while, do) Medium
A. for ($i = 0; $i -le 5; $i++) { $i }
B. for ($i = 1; $i -le 5; $i--) { $i }
C. for ($i = 1; $i -lt 5; $i++) { $i }
D. 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?

Loops (for, foreach, while, do) Medium
A. for ($i = 0; $condition; $i++) { ... }
B. do { ... } while ($condition)
C. while ($condition) { ... }
D. foreach ($item in $items) { ... }

33 Given $names = @('Ana', 'Ben', 'Chen'), which expression returns Ben?

Arrays Medium
A. $names[-1]
B. $names[2]
C. $names[1]
D. $names[0]

34 Given $server = @{ Name = 'WEB01'; Port = 443 }, which expression changes the port value to 8443?

Hashtables Medium
A. $server['Port'] = 8443
B. $server[8443] = 'Port'
C. $server.Add('Port', 8443)
D. $server.Port -eq 8443

35 Which function correctly accepts a name and returns the greeting Hello, Sam when called as Get-Greeting -Name Sam?

Functions Medium
A. function Get-Greeting { param($Name) "Hello, $Name" }
B. function Get-Greeting { return 'Hello, Name' }
C. function Get-Greeting($Name) { 'Hello, Name' }
D. 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?

Scoping Medium
A. Only within that function call
B. Throughout the current script scope
C. Only within the current pipeline
D. Across every future PowerShell session

37 You need a missing file error from Get-Content to be handled by a nearby catch block. Which statement is appropriate?

Basic error handling Medium
A. Get-Content $path -ErrorAction Continue
B. Get-Content $path -ErrorAction Stop
C. Get-Content $path -ErrorAction SilentlyContinue
D. Get-Content $path -ErrorAction Ignore

38 Which command displays the detailed help for Get-Process, including parameter descriptions and examples?

Working with help Medium
A. Get-Command Get-Process -Syntax
B. Get-Member Get-Process -View All
C. Show-Command Get-Process -PassThru
D. 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?

Profiles Medium
A. In the variable named $HOME
B. In the history file from Get-History
C. In the file referenced by $PROFILE
D. In the file referenced by $PSHOME

40 You are currently in the directory containing Report.ps1. Which command explicitly runs that script from the current directory?

Script files Medium
A. ./Report.ps1
B. Report.ps1
C. Import Report.ps1
D. 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?

Introduction to PowerShell Hard
A. Format-Table removes processes whose CPU property is not a string.
B. Format-Table permanently changes the process objects in the operating system.
C. Format-Table converts the stream into formatting objects intended for display.
D. 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?

Console and ISE usage Hard
A. The second tab receives 25 because global scope spans the entire ISE process.
B. The second tab receives 0 because undefined numeric variables default to zero.
C. The second tab receives 25 only while the first tab remains selected.
D. The second tab has no such variable because each tab uses a separate runspace.

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?

Writing scripts Hard
A. The script is rejected before execution because requirements apply globally.
B. The script runs until execution reaches the line containing #Requires.
C. The script runs because the branch containing #Requires is never evaluated.
D. The directive is treated as an ordinary comment outside the first line.

44 What are the final value and runtime type of $x after [int]$x = '5'; $x = '07'?

Variables Hard
A. The value is 7, and the type is System.Int32.
B. The value is 7.0, and the type is System.Double.
C. The value is 07, and the type is System.String.
D. The value is 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?

User input Hard
A. 10, because adding an integer to a string has no effect.
B. 105, because Read-Host returns a string and + concatenates.
C. A type error, because strings and integers cannot use the same operator.
D. 15, because numeric-looking console input is inferred as an integer.

46 What happens when PowerShell parses <# outer <# inner #> outer #> 'Done'?

Comments Hard
A. It reports a parser error because block comments cannot be nested.
B. It comments out the entire remaining session and produces no output.
C. It treats the nested block as a comment and then outputs Done.
D. It treats only 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?

Cmdlets Hard
A. Microsoft.PowerShell.Utility\Get-Date
B. Cmdlet:Get-Date
C. global:Get-Date
D. Get-Date.exe

48 What is the result of (Write-Output -NoEnumerate (1, 2) | Measure-Object).Count?

Pipelines Hard
A. 2, because pipeline input always enumerates arrays automatically.
B. 1, because the array is emitted as one pipeline object.
C. 0, because -NoEnumerate suppresses all pipeline output.
D. 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'?

Operators Hard
A. False, True, False
B. True, True, True
C. True, True, False
D. True, False, True

50 Which branch executes for if (@()) { 'A' } elseif ($null) { 'B' } else { 'C' }?

Conditional statements (if, else, switch) Hard
A. The second branch outputs B.
B. Both conditional branches execute.
C. The first branch outputs A.
D. The final branch outputs C.

51 What does switch -Regex ('cat') { 'a' { 'A' }; '^c' { 'C' }; default { 'D' } } output?

Conditional statements (if, else, switch) Hard
A. A followed by C, because both matching clauses execute.
B. Only A, because the first matching clause ends the switch.
C. A, C, and D, because every clause is evaluated.
D. Only 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 }?

Loops (for, foreach, while, do) Hard
A. 8, because every value except 2 is added.
B. 10, because continue affects only the conditional statement.
C. 7, because the iteration expression is skipped by continue.
D. 6, because execution stops when $i reaches 2.

53 After $a = 1, 2; $b = ,$a, what are $b.Count and $b[0].Count?

Arrays Hard
A. 1 and 1, respectively
B. 2 and 1, respectively
C. 1 and 2, respectively
D. 2 and 2, respectively

54 What does ([ordered]@{ b = 2; a = 1 }).Keys -join ',' produce?

Hashtables Hard
A. a=1,b=2, because entries are converted to strings.
B. b,a, because insertion order is preserved.
C. 1,2, because .Keys returns associated values.
D. 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?

Functions Hard
A. B, P1, P2, P3, E
B. P1, P2, P3
C. B, P3, E
D. 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?

Scoping Hard
A. 1, because the function assignment creates a local variable.
B. A scope error, because $x exists in more than one scope.
C. 2, because child scopes always update their parent variables.
D. $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?

Basic error handling Hard
A. Get-Item writes missing-file messages directly to standard output.
B. Get-Item emits a non-terminating error unless error action is changed.
C. catch handles only syntax errors unless a type name is supplied.
D. try blocks cannot contain cmdlets that access the file system.

58 Which command retrieves help specifically for the Filter parameter of Get-ChildItem?

Working with help Hard
A. Show-Command Get-ChildItem -Help Filter
B. Get-ChildItem -HelpParameter Filter
C. Get-Help Get-ChildItem -Parameter Filter
D. Get-Help Filter -Command Get-ChildItem

59 Which profile path does the automatic variable $PROFILE represent by default?

Profiles Hard
A. All users and all hosts profile
B. All users and the current host profile
C. The current user and all hosts profile
D. The current user and current host profile

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?

Script files Hard
A. . ./SetValue.ps1
B. Start-Process ./SetValue.ps1
C. Invoke-Item ./SetValue.ps1
D. & ./SetValue.ps1