Unit 5 - Practice Quiz

CSC104

1 Which of the following best describes PowerShell?

A. A web browser developed by Microsoft
B. A cross-platform task automation and configuration management framework
C. A strictly GUI-based administration tool
D. A database management system

2 What is the standard file extension for a PowerShell script?

A. .cmd
B. .bat
C. .ps1
D. .vbs

3 What implies the naming convention used for PowerShell Cmdlets?

A. Noun-Verb (e.g., File-Get)
B. Verb-Noun (e.g., Get-Service)
C. Adjective-Noun (e.g., New-File)
D. Subject-Object (e.g., Service-Get)

4 Which character is used to denote a variable in PowerShell?

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

5 Which command is used to update the local help files in PowerShell?

A. Upgrade-Help
B. Get-Help -Update
C. Update-Help
D. Install-Help

6 In the PowerShell ISE, what does the 'ISE' stand for?

A. Integrated Scripting Environment
B. Internal System Executor
C. Interactive Shell Environment
D. Integrated Service Engine

7 How do you create a single-line comment in a PowerShell script?

A. // This is a comment
B. <!-- This is a comment -->
C. # This is a comment
D. ' This is a comment

8 Which syntax represents a multi-line comment block in PowerShell?

A. / Comment /
B. <# Comment #>
C. {{ Comment }}
D. <!-- Comment -->

9 Which cmdlet is used to request input from the user during script execution?

A. Get-Input
B. Read-Host
C. Input-User
D. Ask-Question

10 What is the primary function of the pipeline operator (|)?

A. It acts as a logical OR operator.
B. It redirects output to a file.
C. It passes the output object of one cmdlet as the input to the next cmdlet.
D. It runs commands in the background.

11 Which operator is used for equality comparison in PowerShell?

A. ==
B. =
C. -eq
D. -equals

12 If b = 5, what is the result of b?

A. True
B. False
C. 15
D. Error

13 Which wildcard character represents 'zero or more characters' in string matching?

A. ?
B. *
C. %
D. #

14 How do you define an array containing the numbers 1, 2, and 3?

A. $arr = {1, 2, 3}
B. $arr = [1, 2, 3]
C. $arr = 1, 2, 3
D. $arr = list(1, 2, 3)

15 How do you access the first element of an array named $myArray?

A. $myArray[1]
B. $myArray(0)
C. $myArray[0]
D. $myArray.First

16 What is the correct syntax for creating a hashtable?

A. @{ Key = 'Value' }
B. @( Key = 'Value' )
C. { Key : 'Value' }
D. [ Key = 'Value' ]

17 Which cmdlet is used to filter objects in a pipeline based on specific criteria?

A. Select-Object
B. Where-Object
C. Filter-Object
D. Sort-Object

18 Which cmdlet allows you to pick specific properties from an object and discard the rest?

A. Where-Object
B. Select-Object
C. Get-Member
D. Group-Object

19 What is the default Execution Policy on Windows client operating systems (like Windows 10/11)?

A. Unrestricted
B. RemoteSigned
C. Restricted
D. Bypass

20 Which command allows you to see all available aliases in the current session?

A. Get-Alias
B. Show-Alias
C. List-Alias
D. Get-Command -Type Alias

21 Which mathematical operator represents the modulus (remainder) in PowerShell?

A. %
B. Mod
C. /
D. \

22 Evaluate the following PowerShell expression: 10 -ne 10.

A. True
B. False
C. 10
D. Null

23 Which keyword is used to handle multiple specific conditions in a cleaner way than many elseif blocks?

A. switch
B. case
C. select
D. choose

24 What is the correct syntax for a basic if statement?

A. if b { ... }
B. if (b) { ... }
C. if [b] then ...
D. if (b) then ...

25 Which loop type is best used when you know the exact number of iterations in advance?

A. while
B. do-while
C. for
D. until

26 Which loop ensures that the code block is executed at least once?

A. while loop
B. for loop
C. do-while loop
D. foreach loop

27 What represents the 'current object' in a pipeline iteration (e.g., inside ForEach-Object)?

A. $this
B. PSItem
C. $obj
D. $current

28 To create a function named Get-Time, which keyword is used?

A. def Get-Time
B. func Get-Time
C. function Get-Time
D. cmdlet Get-Time

29 Inside a function, how do you define input variables?

A. Inside a param() block
B. Using input()
C. Using args[] only
D. Inside the begin block

30 What is the scope of a variable defined inside a function by default?

A. Global
B. Script
C. Local (Function)
D. Private

31 How can you modify a variable in the Global scope from inside a function?

A. $global:variableName = 'value'
B. export $variableName
C. $variableName = 'value' -Scope Global
D. Set-Global $variableName

32 Which construct is used for error handling in PowerShell?

A. try...catch...finally
B. if...error...then
C. on error resume next
D. check...handle

33 Which automatic variable contains the error object inside a catch block?

A. $ErrorMsg
B. $Exception
C. $_
D. $Caught

34 What is a PowerShell Profile?

A. A user's login credentials
B. A script that runs automatically when you start PowerShell
C. A configuration file for the Windows Registry
D. A summary of cmdlet usage stats

35 How do you run a script named deploy.ps1 located in the current directory?

A. run deploy.ps1
B. deploy.ps1
C. ./deploy.ps1 or .\deploy.ps1
D. exec deploy.ps1

36 Which cmdlet is used to format output as a table?

A. Format-List
B. Format-Table
C. Out-Table
D. Show-Table

37 What acts as the 'End of Line' or command terminator in PowerShell if you want to put two commands on one line?

A. Comma ,
B. Period .
C. Semicolon ;
D. Pipe |

38 Which operator performs a case-insensitive logical 'AND'?

A. &&
B. AND
C. -and
D. &

39 What is the result of "5" + 5 in PowerShell?

A. 10
B. "55"
C. Error
D. Null

40 How do you cast a variable $x explicitly to an integer?

A. (int)$x
B. [int]$x
C. $x as int
D. convert($x, int)

41 Which cmdlet is used to export data to a CSV file?

A. Out-File
B. Export-Csv
C. Write-Csv
D. ConvertTo-Csv

42 In the variable $env:Path, what does the env: drive represent?

A. The Environment Variable provider
B. The Envelope settings
C. An external hard drive
D. Encryption keys

43 Which loop is designed specifically to iterate over a collection of objects?

A. for
B. while
C. foreach
D. do-until

44 What is the purpose of $ErrorActionPreference?

A. To set the default help language
B. To configure how PowerShell responds to non-terminating errors
C. To set the background color for error messages
D. To log errors to a text file automatically

45 If you want to view the properties and methods of an object, which cmdlet should you pipe it to?

A. Get-Member
B. Show-Object
C. Get-Properties
D. Inspect-Object

46 Which logical operator returns True if either condition is true?

A. -and
B. -xor
C. -or
D. -not

47 Using LaTeX notation, if a variable represents and we want to calculate in PowerShell, which operator is used for the exponent?

A. ^
B. **
C. exp
D. [Math]::Pow()

48 What is the output of the following loop logic?
i++; Write-Output i -lt 3)

A. 0, 1, 2
B. 1, 2, 3
C. 1, 2
D. 0, 1, 2, 3

49 Which parameter in Get-ChildItem allows you to search through subdirectories?

A. -Deep
B. -Recurse
C. -All
D. -Sub

50 Which command stops the current script execution immediately?

A. break
B. pause
C. exit
D. stop