Test your knowledge of PowerShell scripting
Posted on
April 19, 2022
by

PowerShell is a simple scripting language that has been available — mostly, though not exclusively, with Microsoft operating systems — for many years. Questions regarding basic knowledge of PowerShell, which is quite intuitive and simple in operation, appear on certification exams from several vendors. This includes the most recent version of the PenTest+ exam from CompTIA.

Given all of this, it is a good idea to have some familiarity with the language and be able to answer some rudimentary questions about it. What follows is a self-test of 25 questions about PowerShell basics and commands. In all cases, pick the best answer(s) to each question. The answers appear at the end of the questions. Good luck!

1. If $s = “Emmett Dulaney”, what will the command $s[-1] return?
A. 0
B. y
C. false
D. Emmett Dulaney-1

2. After giving the command [int]$mortgage=25000, what will happen when you enter the command $mortgage=”too high”?
A. The mortgage variable will now be a string (“too high”)
B. The mortgage variable will remain an integer (25000)
C. The mortgage variable will remain an integer (0)
D. An error will indicate that you cannot convert value "too high" to type "System.Int32"

3. Which of the following characters is used to use the output of one command as the input for the next?
A. @
B. +
C. |
D. ~

4. Which output stream number is associated with success output?
A. 1
B. 2
C. 3
D. 4

5. What is the expected output from the command:
Get-CimInstance -Class Win32_PingStatus -Filter "Address='127.0.0.1'" | Format-Table -Property IPV4Address,IPV6Address
A. A table showing the status of each loopback address pinged on this machine
B. A two column table showing the IPv4 and IPv6 interface addresses on this machine
C. A table showing the IPv4 and IPv6 address of every interface on the local network
D. An empty table

6. Which command will show the current date and time in PowerShell?
A. TimeOfDay
B. Get-Time
C. Now
D. Get-Date

7. Which of the following commands can be used in PowerShell to see a list of all commands?
A. List-Command
B. Show-Commands
C. Get-Command
D. Get-Commands

8. Which set of cmdlets can be used to get events from event logs and event tracing log files on local and remote computers?
A. Get-WinEvent
B. Get-CounterLogs
C. Get-EventLogs
D. Get-LocalRemote

9. Which of the following is comment character used in PowerShell?
A. :
B. #
C. \
D. @

10. Which of the following will be returned from the command:
“water bottle” -split “r"
A. water
bottle
B. water bottle
C. wate
bottle
D. watebottle

11. Which of the following commands can be used to perform an operation on each item in a collection?
A. Respectively
B. With
C. Against
D. ForEach

12. Within the Windows platform only, PowerShell has cmdlets that interact with CIM Servers (like Windows Management Instrumentation, or WMI) service. What is CIM?
A. Computer Integrated Model
B. Common Information Model
C. Common Interface Manager
D. Center Integrated Management

13. Which of the following commands will change the text hand sanitizer to hand soap?
A. "hand sanitizer" -switch "anitizer" "oap"
B. "hand sanitizer" -change "anitizer" "oap"
C. "hand sanitizer" -swap "anitizer" "oap"
D. "hand sanitizer" -replace "anitizer", "oap"

14. Which cmdlet waits for a job to be in one of the terminating states before continuing on with its execution?
A. Until
B. Wait-Job
C. Suspend
D. Get-Wait

15. On a Windows client (such as Windows 10), what is the start of the default value for $PSHome?
A. C:\Windows\System\
B. C:\Windows\System32\
C. C:\System\
D. C:\

Please visit GoCertify to attempt the remaining 10 questions of this quiz.


ANSWERS

1. B: Only the last character of the variable will be returned — in this case, the “y”.
2. D: Since the variable has been declared as an integer, it can only be changed to another value that is also an integer. An attempt to assign it a string will result in the error message.
3. C: The pipe character ( | ) is used to use the output from one command as the input to another.
4. A: Success output is equal to 1, errors are 2, warnings are 3, verbose output is 4, and debug messages are 5.
5. B: The command given will run ping on the loopback address and then format a table and show the IPv4 and IPv6 values in separate columns.
6. D: The cmdlet Get-Date will show the current date and time.
7. C: Get-Command is used to see a lift of all commands in PowerShell.
8. A: The cmdlet Get-Win Event can be used to get events from event logs and tracing log files both on the local machine and remote computers.
9. B: As with many programming languages, the pound sign (#)is used to denote comments.
10. C: The -split command will split the value into separate lines — essentially replacing the value given (“r”, in this case) with a newline character. Since the next character in the original string is a blank space, that becomes the first character in the second line of the output in this instance.
11. D: For Each can be used to repeat the operation for each item in the collection (an array, a set of variables, etc.).
12. B: While the acronym can have many definitions, as it relates to PowerShell, CIM stands for Common Information Model.
13. D: The -replace command will change one value for another.
14. B: The Wait-Job cmdlet will wait for a job to be in a terminating state before continuing execution.
15. B: On Windows hosts, PowerShell is, by default, installed beneath C:\Windows\Sysem32\.

About the Author

Emmett Dulaney is a professor at Anderson University and the author of several books including Linux All-in-One For Dummies and the CompTIA Network+ N10-008 Exam Cram, Seventh Edition.

Posted to topic:
Certification

Important Update: We have updated our Privacy Policy to comply with the California Consumer Privacy Act (CCPA)

CompTIA IT Project Management - Project+ - Advance Your IT Career by adding IT Project Manager to your resume - Learn More