What is the correct syntax for arrays in powershell?

Example 1:

Note 2: the comma is also used so the individual elements in the array {0, -30}

Example 2:

To create an array, we create a variable and assign an array. Arrays are marked with an @. Let's discuss above and use an array to connect to several remote computers: $ strComputers = @ ("Server1", "Server2", "Server3")

So which one is correct or what is the difference?

+5
source share
2 answers

Example 2 uses the syntax cast array, which allows, for example, to consider a single element as an array:

$myList = @("Hello")

, , , , :

$myArray = @(Get-Process Excel)

, , :

$myArray = "hello", "world", "again"

( )

+13

, operator :

[PS] C:\>$a = ,"Hello World"

[PS] C:\>$a.gettype()


IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array


[PS] C:\>$a.count

1
+3

All Articles