Pass array from cmd.exe batch to powershell script
Consider the following script: array as parameter.ps1
When calling from command line cmd.exe using the following command
powershell -file ".\array as parameter.ps1" -data "data1","data2"
outputs
items in data array: 1
first item in data array: data1,data2
But when calling using the folloing command
powershell -command "&{.\'array as parameter.ps1' -data 'data1','data2'}"
outputs
items in data array: 2
first item in data array: data1
#requires -version 2.0
[CmdletBinding()]
param (
[parameter(Mandatory=$false)] [string[]] $data
)
write-host "items in data array:" $data.count
write-host "first item in data array:" $data[0]
[CmdletBinding()]
param (
[parameter(Mandatory=$false)] [string[]] $data
)
write-host "items in data array:" $data.count
write-host "first item in data array:" $data[0]
When calling from command line cmd.exe using the following command
powershell -file ".\array as parameter.ps1" -data "data1","data2"
outputs
items in data array: 1
first item in data array: data1,data2
But when calling using the folloing command
powershell -command "&{.\'array as parameter.ps1' -data 'data1','data2'}"
outputs
items in data array: 2
first item in data array: data1
Comments