$variable = "test", "test1", "test2", "","test3"
Write-Host $variable
foreach($item in $variable)
{
if (-not $item -or $item -eq "") {
$item ="N/A"
}
}
Write-Host $variable
- this is the OuptPut: test test1 test2 test3
- this is what I expect : test test1 test2 N/A test3
Strings in .NET are immutable and passed by value - and when you assign a new value to
$itemit won't affect the existing string value extracted from$variablearray.Use a
forloop to write back to the array: