【发布时间】:2019-03-01 14:05:53
【问题描述】:
我有一个对象数组,例如:
$arrayServ = New-Object System.Collections.ArrayList(,$serv)
这个数组包含一些对象,例如:
name prefix tenants
---- ------ -------
TOTO http://home/toto bob, michael, ramy, anna
Nav http://8.8.8.8/google com, uk, fr
我正在尝试提取属性name 中的所有数据并将它们放入一个变量中,并将该变量与另一个变量连接起来,该变量是name 的计数器。
类似这样的:
$liste = "$i. $arrayServ [$i]"
我为什么要这样做?这是因为,我想在 InputBox 中显示 $liste,例如:
$liste = "$i. $arrayServ [$i]"
$msg = $liste -join "`n"
$item = InputBox $msg -title "Your choice"
输入框“您的选择”
请问有人知道我该怎么做吗?
【问题讨论】:
-
添加到arraylist的时候,里面有什么?
,$Serv通常是一个 array 表示法,它将数组放入arraylist 作为一个数组 而不是作为一系列对象。所以...你从$arrayServ[0].GetType()和$arrayServ[1].GetType()得到什么? -
顺便说一句:请避免使用伪方法语法:而不是
New-Object SomeType(arg1, ...),使用New-Object SomeType [-ArgumentList] arg1, ...- PowerShell cmdlet 和函数的调用方式类似于 shell 命令(无括号、空格- 分隔的参数),不像 methods.
标签: powershell variables concatenation inputbox arrayobject