exam questions

Exam PT0-002 All Questions

View all questions & answers for the PT0-002 exam

Exam PT0-002 topic 1 question 205 discussion

Actual exam question from CompTIA's PT0-002
Question #: 205
Topic #: 1
[All PT0-002 Questions]

The following PowerShell snippet was extracted from a log of an attacker machine:



A penetration tester would like to identify the presence of an array. Which of the following line numbers would define the array?

  • A. Line 8
  • B. Line 13
  • C. Line 19
  • D. Line 20
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ronniehaang
Highly Voted 2 years ago
Selected Answer: A
to create an array named $A that contains the seven numeric (int) values of 22, 5, 10, 8, 12, 9, and 80, type: $A = 22,5,10,8,12,9,80
upvoted 5 times
...
Itsmebigal
Most Recent 3 weeks ago
Selected Answer: A
Please remember that this is PS1 not your typical high-level langs like python. Defining an array is different here. The square brackets syntax is typically used in languages like Python or JavaScript to denote arrays or lists, but is not the standard way to define an array in PS1. In PowerShell, to define an array, you typically use commas to separate the elements, like this: $crackedpd = 22, 30, 44, 55 or if you want to explicitly create an array, you can use the array subexpression operator $crackedpd = @(22, 30, 44, 55)
upvoted 1 times
...
Ta2oo
3 months, 1 week ago
Selected Answer: A
The correct answer is A. Microsoft state that defining an array in this format $cat = 22, 25, 80, 443 is valid. https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.4
upvoted 1 times
...
StillFiguringItOut
4 months, 3 weeks ago
Selected Answer: B
An array must have the [] so it is not A, C or D
upvoted 1 times
...
Etc_Shadow28000
6 months, 1 week ago
Selected Answer: B
B. Line 13 Explanation: On Line 13, the variable crackedpd is assigned the value [192, 168, 1, 2], which is an array in the context of the script. Arrays are defined by using square brackets [] and including multiple values separated by commas. A. Line 8: • Line 8 assigns the variable $cat a value of 22, 25, 80, 443, but this is done without the square brackets [], so it is not defined as an array here. C. Line 19: • Line 19 contains the expression $crackedp = (192, 168, 1, 1) + $cat, which appears to be an attempt to concatenate values, but it is not defining an array. D. Line 20: • Line 20 contains a While loop and does not define an array.
upvoted 2 times
...
surfuganda
9 months, 3 weeks ago
Selected Answer: A
A. Line 8 [CORRECT] In PowerShell, when you separate values by commas without enclosing them in brackets, it automatically creates an array with those values. This shorthand syntax allows for more concise code and is commonly used, especially when defining arrays with a small number of elements. B. Line 13 [INCORRECT] Because it uses square brackets without the @() notation to define the array. In PowerShell, square brackets are used for type casting, not for defining arrays. C. Line 19 [INCORRECT] Because it attempts to add two arrays together using the + operator. In PowerShell, the + operator is used for arithmetic addition, concatenation of strings, or merging of arrays. you can use the + operator, but you need to ensure that both operands are arrays. AND, you need to use the @() notation to explicitly define the array, even if you're using the shorthand syntax. D. Line 20 [INCORRECT] Same as option [B]
upvoted 1 times
...
LiveLaughToasterBath
11 months, 2 weeks ago
Selected Answer: A
From Microsoft: Other syntax It's commonly understood that @() is the syntax for creating an array, but comma-separated lists work most of the time. PowerShell $data = 'Zero','One','Two','Three'
upvoted 1 times
...
ElDirec
11 months, 3 weeks ago
Selected Answer: A
Let's analyze each option: a) $cat = 22, 25, 80, 443 This is a valid array in PowerShell. The comma , is used to create an array. b) $crackedpd = [192,168,1,2] This is not a valid array. The use of square brackets [] typically denotes an array in some programming languages, but in PowerShell, it's not the correct syntax for creating an array. c) $crackedpd = (192,168,1,1) + $cat This is a valid array creation, but it's combining the elements of two arrays. The result may not be a single array with all the elements but rather a concatenation of two arrays. d) } This is not an array. It appears to be a closing curly brace }, which might be part of some code block, but it doesn't define an array. So, the correct answer is: a) $cat = 22, 25, 80, 443
upvoted 1 times
...
glenpharmd
1 year, 8 months ago
ANSWER=A. WHY, See this search for array creation in powershell script. Now, we will see how to remove multiple items from PowerShell ArrayList by using the RemoveRange() method. $X=2,4,6,8,9,20,5 $y=[System.Collections.ArrayList]$X $y.RemoveRange(1,2) As you can see the arrat has no brackets and no periods. IT HAS SEMICOLLINS TO SEPERATE THE LISTED ITEMS OR VALUES.
upvoted 1 times
...
[Removed]
1 year, 8 months ago
Selected Answer: B
Line 8 defines a comma-separated list of integers, which is not an array. Although arrays can be defined using a comma-separated list, they are enclosed in square brackets, like in line 13. Therefore, line 13 defines an array, containing the integers 192, 168, 1, and 2. Line 13 defines the array "crackedpd" as an array of integers with four elements.
upvoted 1 times
[Removed]
1 year, 8 months ago
Changed to A. Line 8. PowerShell does not require brackets for defining an array. In fact, the code on line 8 is defining an array containing the values 22, 25, 80, and 443.
upvoted 2 times
...
...
[Removed]
1 year, 11 months ago
A is correct
upvoted 2 times
...
ronniehaang
2 years ago
Selected Answer: A
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays?view=powershell-7.3
upvoted 4 times
...
Treebeard88
2 years, 1 month ago
Selected Answer: B
Array brackets used in B
upvoted 2 times
Lagmental
2 years ago
In powershell you dont need brackets to set up an array. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays?view=powershell-7.3
upvoted 4 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago