AngelicCore
AngelicCore

Reputation: 1453

Accessing array element in powershell - ignores [ ] indexers

I have a simple powershell script that sends mail after it finishes running

I have always used [] to access array elements without any problem

$isInstalled = "Yes No Yes" etc
$isInstalled[0] = "Yes"

The problem appears when trying to access the elements from within a string [html body]

Within the html body it only reads the array object and displays the [] as characters, so it goes like this:

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>

results in Yes No Yes[0] instead of Yes.

How can I tell powershell to take the indexer as well into account?

Upvotes: 0

Views: 127

Answers (1)

arco444
arco444

Reputation: 22831

Two things to change. declare the array properly:

$isInstalled = "Yes", "No", "Yes"

And use the correct way of interpolating the variable in format $($var[index])

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

Upvotes: 2

Related Questions