简体   繁体   English

Foreach-Object项目到数组,而不是子数组

[英]Foreach-Object items to an array, not a sub-array

So, I have this script I've been developing, I've changed around from pscustom objects, to hashtables, to splatted arrays, and to simple csv arrays, i've messed around with standard loops, do until, mixing standard loops with foreach-object, and honestly, there is an easy way to solve this problem, but i'd really prefer it not be the solution I use, lol. 所以,我有这个脚本我一直在开发,我已经从pscustom对象,哈希表,splatted数组,到简单的csv数组,我已经乱搞标准循环,直到混合标准循环与foreach-object,老实说,有一种简单的方法可以解决这个问题,但我真的更喜欢它不是我使用的解决方案,哈哈。

So what's happening is, this variable will LOOK like it's outputting to to the correct format if I encapsulate the % loop in parenthesis... but in order to select the first or second string with the output there, I have to use 2 sets of brackets instead of just one. 所以正在发生的事情是,如果我将%循环封装在括号中,这个变量将会像输出到正确的格式一样...但是为了选择带有输出的第一个或第二个字符串,我必须使用2组括号而不是一个。 so for instance, $vm[0][0], $vm[0][1] 例如,$ vm [0] [0],$ vm [0] [1]

not entirely sure this method will work, but I've been trying some crazy stuff. 不完全确定这种方法会起作用,但我一直在尝试一些疯狂的东西。

$vm = ( $d[1] , $l[1] | % { $_ + '\VM\VMWare' } ) , '\setup.exe' , '\setup64.exe' , '/s /v "/qn reboot=r"'

In order not to be jagged array, enclose the whole in @() . 为了不是锯齿状数组,将整体包含在@() And use a semicolon as a separator. 并使用分号作为分隔符。

$vm = @($d[1],$l[1] | % { $_ + '\VM\VMWare' }; '\setup.exe', '\setup64.exe', '/s /v "/qn reboot=r"')

or 要么

$vm = @(
    $d[1],$l[1] | % { $_ + '\VM\VMWare' }
    '\setup.exe', '\setup64.exe', '/s /v "/qn reboot=r"'
)

Another way is to add one array to the other. 另一种方法是将一个数组添加到另一个数组。

$vm = @($d[1],$l[1] | % { $_ + '\VM\VMWare' }) + '\setup.exe', '\setup64.exe', '/s /v "/qn reboot=r"'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM