Html 访问powershell中的数组元素-忽略[]索引器

Html 访问powershell中的数组元素-忽略[]索引器,html,arrays,string,powershell,Html,Arrays,String,Powershell,我有一个简单的powershell脚本,它在运行完成后发送邮件 我一直使用[]来访问数组元素,没有任何问题 $isInstalled = "Yes No Yes" etc $isInstalled[0] = "Yes" 尝试从字符串[html正文]中访问元素时出现问题 在html正文中,它只读取数组对象并将[]显示为字符, 所以它是这样的: return "<td class='tg-yw4l'>$isInstalled[0]</td>" Write-Host Cal

我有一个简单的powershell脚本,它在运行完成后发送邮件

我一直使用[]来访问数组元素,没有任何问题

$isInstalled = "Yes No Yes" etc
$isInstalled[0] = "Yes"
尝试从字符串[html正文]中访问元素时出现问题

在html正文中,它只读取数组对象并将[]显示为字符, 所以它是这样的:

return "<td class='tg-yw4l'>$isInstalled[0]</td>"

Write-Host CallFunctionX
<td class='tg-yw4l'> Yes Yes Yes Yes Yes Yes Yes Yes Yes No[0]</td>
返回“$isInstalled[0]”
写主机调用函数x
是是是是否[0]
结果为
是否是[0]
而不是
Yes


如何让powershell也考虑索引器?

需要更改两件事。正确声明数组:

$isInstalled = "Yes", "No", "Yes"
并使用格式为
$($var[index])

return“$($isInstalled[0])”

有两件事需要改变。正确声明数组:

$isInstalled = "Yes", "No", "Yes"
并使用格式为
$($var[index])

return“$($isInstalled[0])”

数组声明为:[string[]]$isInstalled=”“,循环添加如下内容:$isInstalled+=“No”尝试了您的答案-第一部分不需要,但第二部分可以工作…谢谢!数组声明为:[string[]$isInstalled=”“,循环添加如下内容:$isInstalled+=“No”尝试了您的答案-第一部分不必要,但第二部分有效…谢谢!