Exam PT0-002 All QuestionsBrowse all questions from this exam
Question 205

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?

    Correct Answer: B

    Line 13 defines an array. In PowerShell, an array can be identified by the use of square brackets, which explicitly enclose multiple values separated by commas, like [192, 168, 1, 2] in line 13. Line 8, although it contains a comma-separated list of integers, does not explicitly use the square brackets to define an array and is assigning values to a variable, which is different in the context of the PowerShell script. Therefore, line 13 is the one that defines the array explicitly.

Discussion
ronniehaangOption: 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

ronniehaangOption: A

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays?view=powershell-7.3

Etc_Shadow28000Option: 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.

[Removed]Option: A

A is correct

Treebeard88Option: B

Array brackets used in B

Lagmental

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

surfugandaOption: 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]

LiveLaughToasterBathOption: 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'

ElDirecOption: 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

glenpharmdOption: A

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.

[Removed]Option: 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.

[Removed]

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.