To complement Mathias helpful answer, which shows in-place modification of an array, with an alternative that creates a new array, taking advantage of the fact that you can use entire statements as expressions in PowerShell, with the results getting automatically collected in an array (if there are two or more output objects).
$variable = "test", "test1", "test2", "","test3"
# Note:
# If you want to ensure that $variable remains an array even if the loop
# outputs just *one* string, use:
# [array] $variable = ...
$variable =
foreach ($item in $variable) { if (-not $item) { 'N/A' } else { $item } }
Note:
-not $item
is sufficient to detect both an empty string an a $null
value, based on PowerShell's automatic to-Boolean conversion rules, which are summarized in the bottom section of this answer.
While in-place updating is more memory-efficient, with smallish arrays creating a new one isn't a concern.