Avatar of Alan Varga
Alan Varga
Flag for United States of America

asked on 

Powershell String Array Initialization Does Not Allow Concatenation?

Why does this return the first element of my array:
[string] $PsFolder = "C:\Workshop\PowerShell-work"
[array] $Commands = @(
    "\Get PS version.ps1",
    "\List mapped drives.ps1"
    "\Services\ListServices.ps1",
    $ComputerFolder + "\Hardware\Network adapters\Switchboard-network adapters.ps1",
    "Quit"
)
$Commands[0]

Open in new window

but this returns all of the elements as one string:
[string] $PsFolder = "C:\Workshop\PowerShell-work"
[array] $Commands = @(
    $PsFolder + "\Get PS version.ps1",
    "\List mapped drives.ps1"
    "\Services\ListServices.ps1",
    $ComputerFolder + "\Hardware\Network adapters\Switchboard-network adapters.ps1",
    "Quit"
)
$Commands[0]

Open in new window

For this switchboard I want to point to several folders to bring a number of scripts together in one place.
Powershell

Avatar of undefined
Last Comment
Chris Dent

8/22/2022 - Mon