×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

PowerShell MCQs (Multiple-Choice Questions)

Practice these PowerShell MCQs (Multiple-Choice Questions) with answers and explanations to test your knowledge of PowerShell commands, scripting, variables, pipelines, functions, modules, remoting, error handling, objects, and automation.

PowerShell MCQs

These PowerShell multiple-choice questions cover fundamental and intermediate concepts, including cmdlets, variables, operators, objects, pipelines, filtering, formatting, functions, scripts, modules, remoting, jobs, and error handling.

List of PowerShell MCQs

The following PowerShell MCQs are useful for students, developers, system administrators, automation engineers, and candidates preparing for technical interviews and certification examinations.

1. What is PowerShell primarily used for?

  1. Image editing
  2. Command-line administration and automation
  3. Database-only development
  4. Web browser development

Answer: B) Command-line administration and automation

Explanation:

PowerShell is a command-line shell and scripting language designed for automation, administration, and management tasks.

2. Which file extension is commonly used for a PowerShell script?

  1. .ps1
  2. .bat
  3. .cmd
  4. .sh

Answer: A) .ps1

Explanation:

PowerShell script files normally use the .ps1 extension.

3. What is a PowerShell cmdlet?

  1. A compiled Windows driver
  2. A lightweight PowerShell command designed for a specific task
  3. A database table
  4. An HTML element

Answer: B) A lightweight PowerShell command designed for a specific task

Explanation:

Cmdlets are specialized PowerShell commands that perform specific operations and generally follow a Verb-Noun naming convention.

4. Which cmdlet displays information about PowerShell commands and concepts?

  1. Get-Command
  2. Get-Help
  3. Get-Info
  4. Show-Help

Answer: B) Get-Help

Explanation:

Get-Help displays information about PowerShell commands, concepts, providers, scripts, and other help topics.

5. Which cmdlet is used to discover available PowerShell commands?

  1. Get-Command
  2. Get-Available
  3. Find-CommandOnly
  4. Search-Command

Answer: A) Get-Command

Explanation:

Get-Command retrieves commands available on the system, including cmdlets, functions, aliases, scripts, and applications.

6. Which symbol represents the PowerShell pipeline operator?

  1. >
  2. |
  3. ->
  4. ::

Answer: B) |

Explanation:

The pipe character | sends the output objects from one command to another command.

7. What does PowerShell primarily pass through a pipeline?

  1. Only plain text
  2. Only file names
  3. Objects
  4. Only XML documents

Answer: C) Objects

Explanation:

PowerShell pipelines pass .NET objects between commands, allowing subsequent commands to work with their properties and methods.

8. Which syntax is used to create a PowerShell variable named name?

  1. var name = "John"
  2. $name = "John"
  3. @name = "John"
  4. #name = "John"

Answer: B) $name = "John"

Explanation:

PowerShell variables are identified by a dollar sign. The assignment $name = "John" stores the string in the variable.

9. Which variable contains the most recent error records?

  1. $Error
  2. $Errors
  3. $LastError
  4. $Exception

Answer: A) $Error

Explanation:

$Error stores recent PowerShell error records, with the most recent error at index 0.

10. Which automatic variable indicates whether the last operation succeeded?

  1. $Success
  2. $?
  3. $Result
  4. $Status

Answer: B) $?

Explanation:

$? contains a Boolean value indicating whether the last operation succeeded. For native commands, the result is also related to the command's exit code.

11. Which cmdlet is commonly used to retrieve running processes?

  1. Get-Process
  2. Get-Task
  3. Read-Process
  4. Find-Process

Answer: A) Get-Process

Explanation:

Get-Process retrieves process objects representing processes running on the computer.

12. Which cmdlet retrieves files and directories from a location?

  1. Get-ChildItem
  2. Get-Directory
  3. Read-Folder
  4. Get-FilesOnly

Answer: A) Get-ChildItem

Explanation:

Get-ChildItem retrieves items such as files and directories from a specified location.

13. Which cmdlet is used to filter objects in a PowerShell pipeline?

  1. Where-Object
  2. Filter-Object
  3. Select-Filter
  4. Find-Object

Answer: A) Where-Object

Explanation:

Where-Object selects objects based on property values or a filtering script block.

14. What does $_ represent inside a typical Where-Object script block?

  1. The current pipeline object
  2. The current computer name
  3. The previous command
  4. The current PowerShell version

Answer: A) The current pipeline object

Explanation:

Inside a pipeline script block, $_ refers to the current object being processed.

15. Which cmdlet selects specific properties from objects?

  1. Select-Object
  2. Choose-Property
  3. Get-Property
  4. Pick-Object

Answer: A) Select-Object

Explanation:

Select-Object can select specified properties, create calculated properties, or select a specified number of objects.

16. Which cmdlet sorts objects by property values?

  1. Order-Object
  2. Sort-Object
  3. Arrange-Object
  4. Order-By

Answer: B) Sort-Object

Explanation:

Sort-Object sorts objects by one or more specified properties. It can also sort in descending order.

17. Which operator is commonly used for equality comparison in PowerShell?

  1. ==
  2. =
  3. -eq
  4. :=

Answer: C) -eq

Explanation:

PowerShell uses comparison operators such as -eq, -ne, -gt, and -lt.

18. Which operator means "not equal to" in PowerShell?

  1. -neq
  2. -ne
  3. !=
  4. -not-equal

Answer: B) -ne

Explanation:

The -ne comparison operator tests whether two values are not equal.

19. Which operator is used for logical AND?

  1. -and
  2. -all
  3. -both
  4. -join

Answer: A) -and

Explanation:

The -and operator returns true when both Boolean expressions evaluate to true.

20. Which operator performs string matching using a regular expression?

  1. -match
  2. -regex
  3. -pattern
  4. -regexp

Answer: A) -match

Explanation:

The -match operator performs regular-expression matching against strings.

21. Which cmdlet executes an operation for each object received from a pipeline?

  1. ForEach-Object
  2. Each-Object
  3. Process-Object
  4. Loop-Object

Answer: A) ForEach-Object

Explanation:

ForEach-Object performs an operation against each input object. The current object can commonly be accessed through $_.

22. Which statement correctly creates an array containing three values?

  1. $a = 1, 2, 3
  2. $a = {1, 2, 3}
  3. $a = <1,2,3>
  4. $a = array(1,2,3)

Answer: A) $a = 1, 2, 3

Explanation:

Comma-separated expressions create an array in PowerShell. Therefore, $a = 1, 2, 3 creates an array containing three elements.

23. Which syntax creates a PowerShell hashtable?

  1. @{Name="John"; Age=30}
  2. #{Name="John"; Age=30}
  3. [Hash](Name="John")
  4. Hashtable(Name="John")

Answer: A) @{Name="John"; Age=30}

Explanation:

PowerShell hashtables use the @{ } syntax. Keys and values are separated using the assignment operator.

24. Which type accelerator explicitly represents a PowerShell hashtable?

  1. [System.Array]
  2. [System.Collections.Hashtable]
  3. [System.Dictionary]
  4. [System.Hash]

Answer: B) [System.Collections.Hashtable]

Explanation:

A standard PowerShell hashtable is an instance of System.Collections.Hashtable.

25. What is the purpose of the [ordered] type accelerator?

  1. To create an ordered dictionary
  2. To sort every pipeline automatically
  3. To create a sorted array only
  4. To prevent duplicate values

Answer: A) To create an ordered dictionary

Explanation:

[ordered] creates an ordered dictionary whose keys retain the order in which they were added.

26. Which keyword is used to define a PowerShell function?

  1. function
  2. def
  3. func
  4. method

Answer: A) function

Explanation:

PowerShell functions are declared using the function keyword followed by the function name and its script block.

27. Which syntax correctly defines a simple PowerShell function?

  1. function Test-Message { "Hello" }
  2. def Test-Message(): "Hello"
  3. function = Test-Message()
  4. func Test-Message => "Hello"

Answer: A) function Test-Message { "Hello" }

Explanation:

PowerShell functions use a script block enclosed in braces after the function name.

28. Which attribute is commonly used to make a PowerShell function an advanced function?

  1. [AdvancedFunction()]
  2. [CmdletBinding()]
  3. [PowerShellFunction()]
  4. [FunctionBinding()]

Answer: B) [CmdletBinding()]

Explanation:

[CmdletBinding()] enables cmdlet-like behavior and common parameters for advanced functions.

29. Which keyword is commonly used to return a value explicitly from a PowerShell function?

  1. return
  2. yield
  3. output
  4. result

Answer: A) return

Explanation:

The return keyword can explicitly return control and an optional value from a function.

30. Which cmdlet is used to import a PowerShell module?

  1. Import-Module
  2. Load-Module
  3. Use-Module
  4. Open-Module

Answer: A) Import-Module

Explanation:

Import-Module loads a module into the current PowerShell session so its exported commands and other members can be used.

31. Which cmdlet displays modules currently loaded in the PowerShell session?

  1. Get-Module
  2. Show-Module
  3. List-Module
  4. Read-Module

Answer: A) Get-Module

Explanation:

Get-Module displays information about modules loaded in the current session. The -ListAvailable parameter can be used to find installed modules that are available for import.

32. Which cmdlet can be used to display detailed information about a PowerShell object?

  1. Get-Member
  2. Get-ObjectInfo
  3. Show-Type
  4. Inspect-Object

Answer: A) Get-Member

Explanation:

Get-Member displays members such as properties and methods of objects passed to it.

33. Which cmdlet is used to display output in a customized table-like format?

  1. Format-Table
  2. Format-Grid
  3. Show-Table
  4. Convert-Table

Answer: A) Format-Table

Explanation:

Format-Table formats objects as a table for display in the PowerShell host.

34. Which cmdlet formats objects as a list of properties?

  1. Format-List
  2. Format-Properties
  3. Show-List
  4. Display-List

Answer: A) Format-List

Explanation:

Format-List displays object properties in a list-oriented format.

35. Which cmdlet measures properties such as the number of objects in a pipeline?

  1. Measure-Object
  2. Count-Object
  3. Measure-Items
  4. Calculate-Object

Answer: A) Measure-Object

Explanation:

Measure-Object can count objects and calculate numerical statistics such as sum, average, minimum, and maximum for appropriate properties.

36. Which cmdlet writes text to the PowerShell host display?

  1. Write-Host
  2. Print-Console
  3. Display-Text
  4. Console-Write

Answer: A) Write-Host

Explanation:

Write-Host writes output directly to the PowerShell host display. It is intended for host-oriented display rather than general pipeline output.

37. Which cmdlet reads input from the user at the console?

  1. Read-Host
  2. Get-ConsoleInput
  3. Read-Console
  4. Input-Host

Answer: A) Read-Host

Explanation:

Read-Host reads a line of input from the user in the console.

38. Which common parameter causes a command to ask for confirmation before performing an operation?

  1. -Confirm
  2. -Ask
  3. -Prompt
  4. -Approve

Answer: A) -Confirm

Explanation:

The -Confirm common parameter requests confirmation before a command performs an operation that supports confirmation.

39. Which common parameter shows what a command would do without actually performing the operation?

  1. -WhatIf
  2. -Preview
  3. -Simulate
  4. -TestRun

Answer: A) -WhatIf

Explanation:

The -WhatIf parameter allows supported commands to describe the operation they would perform without executing it.

40. Which structure is used for exception handling in PowerShell?

  1. try/catch/finally
  2. attempt/handle/end
  3. error/catch/end
  4. try/error/stop

Answer: A) try/catch/finally

Explanation:

PowerShell uses try, catch, and optionally finally to handle terminating errors and perform cleanup.

41. Which option can make a non-terminating error become terminating for a command?

  1. -ErrorAction Stop
  2. -Error Stop
  3. -StopOnError
  4. -TerminateError

Answer: A) -ErrorAction Stop

Explanation:

-ErrorAction Stop escalates applicable non-terminating errors into terminating errors so that they can be handled by catch.

42. Which preference variable controls the default behavior for many non-terminating errors?

  1. $ErrorActionPreference
  2. $ErrorPreference
  3. $ActionPreference
  4. $ExceptionPreference

Answer: A) $ErrorActionPreference

Explanation:

$ErrorActionPreference controls how PowerShell responds to errors in the current scope and child scopes. Values include Continue, Stop, SilentlyContinue, and others.

43. Which keyword explicitly generates a terminating error in PowerShell?

  1. throw
  2. raise
  3. error
  4. fail

Answer: A) throw

Explanation:

The throw keyword generates a script-terminating error unless the error is handled by an appropriate error-handling construct.

44. Which cmdlet can be used to run a command on a remote computer?

  1. Invoke-Command
  2. Remote-Command
  3. Run-Remote
  4. Start-RemoteCommand

Answer: A) Invoke-Command

Explanation:

Invoke-Command can execute commands or script blocks on one or more remote computers.

45. Which cmdlet creates a persistent PowerShell session?

  1. New-PSSession
  2. New-RemoteConnection
  3. Open-PSSession
  4. Connect-PowerShell

Answer: A) New-PSSession

Explanation:

New-PSSession creates a persistent PowerShell session that can be reused for multiple commands. Such sessions can be used with Invoke-Command.

46. Which cmdlet starts an interactive session with a remote computer?

  1. Enter-PSSession
  2. Start-RemoteSession
  3. Open-PSSession
  4. Connect-RemoteHost

Answer: A) Enter-PSSession

Explanation:

Enter-PSSession starts an interactive PowerShell session with a remote computer or an existing PSSession.

47. Which automatic variable contains the exit code of the last native program that ran?

  1. $LASTEXITCODE
  2. $EXITCODE
  3. $LASTSTATUS
  4. $NativeExit

Answer: A) $LASTEXITCODE

Explanation:

$LASTEXITCODE contains the exit code returned by the last native program that ran. A zero exit code conventionally indicates success.

48. Which syntax correctly creates a simple conditional statement in PowerShell?

  1. if ($x -gt 10) { "Large" }
  2. if $x > 10 then "Large"
  3. if ($x > 10): "Large"
  4. when ($x -gt 10) { "Large" }

Answer: A) if ($x -gt 10) { "Large" }

Explanation:

PowerShell uses the if keyword followed by a Boolean expression and a script block containing the statements to execute.

49. What does the following PowerShell command output?

$numbers = 1, 2, 3
$numbers | Where-Object { $_ -gt 1 }
  1. Only 1
  2. 1 and 2
  3. 2 and 3
  4. 1, 2, and 3

Answer: C) 2 and 3

Explanation:

Where-Object keeps only values for which the condition is true. The expression $_ -gt 1 is true for 2 and 3, so those two values are returned.

50. What does the following PowerShell command return?

Get-Process |
    Where-Object { $_.CPU -gt 100 } |
    Select-Object Name, CPU |
    Sort-Object CPU -Descending
  1. All processes sorted by process name
  2. Processes with CPU greater than 100, showing Name and CPU, sorted by CPU descending
  3. Only the process with the highest CPU usage
  4. All processes with only their CPU property displayed

Answer: B) Processes with CPU greater than 100, showing Name and CPU, sorted by CPU descending

Explanation:

Get-Process produces process objects. Where-Object filters them to processes whose CPU property is greater than 100. Select-Object keeps only the Name and CPU properties, and Sort-Object CPU -Descending orders the resulting objects from highest CPU value to lowest.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2026 www.includehelp.com. All rights reserved.