Unit 5 - Practice Quiz

CSC104 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which of the following best describes PowerShell?

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

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

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

3 What implies the naming convention used for PowerShell Cmdlets?

A. Adjective-Noun (e.g., New-File)
B. Verb-Noun (e.g., Get-Service)
C. Subject-Object (e.g., Service-Get)
D. Noun-Verb (e.g., File-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. Install-Help
C. Get-Help -Update
D. Update-Help

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

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

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. Ask-Question
B. Read-Host
C. Get-Input
D. Input-User

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

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

11 Which operator is used for equality comparison in PowerShell?

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

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

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

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 = list(1, 2, 3)
C. $arr = [1, 2, 3]
D. $arr = {1, 2, 3}

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

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

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. Sort-Object
D. Filter-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. Bypass
C. RemoteSigned
D. Restricted

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

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

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

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

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

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

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

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

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

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

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. for loop
B. while loop
C. foreach loop
D. do-while loop

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

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

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

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

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

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

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

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

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

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

32 Which construct is used for error handling in PowerShell?

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

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

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

34 What is a PowerShell Profile?

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

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

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

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

A. Format-Table
B. Format-List
C. Show-Table
D. Out-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. Semicolon ;
C. Pipe |
D. Period .

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

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

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

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

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. Write-Csv
B. Export-Csv
C. ConvertTo-Csv
D. Out-File

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

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

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

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

44 What is the purpose of $ErrorActionPreference?

A. To set the default help language
B. To set the background color for error messages
C. To configure how PowerShell responds to non-terminating errors
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. Inspect-Object
B. Show-Object
C. Get-Member
D. Get-Properties

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

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

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

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

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

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

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

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

50 Which command stops the current script execution immediately?

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