I am attempting to use a single element of an array, when creating a string message, but it is using both elements, concatenated by a space, whether I use $myArray[0] or $myArray[1]...
# Multiple distinct log folders found
Write-Host "Multiple script directories were found in the command list."
Write-Host "Which folder would you like to use for logging?"
for ($i = 0; $i -lt $uniqueLogFolders.Count; $i++) {
$marker = if ($i -eq 0) { " (default)" } else { "" }
Write-Host "$($i+1). $uniqueLogFolders[$i]$marker"
}
$choice = Read-Host "Enter the number of the folder to use [default = 1]"
When debugging in Visual Studio, I can clearly see that the 2 element array is, as I expect it to be, containing 2 unique folders...
But the resulting output is as follows...
Multiple script directories were found in the command list. Which folder would you like to use for logging?
- C:\Users\Todd\source\repos\MyProject\.scripts\logs C:\Users\Todd\source\repos\MyProject\logs[0] (default)
- C:\Users\Todd\source\repos\MyProject\.scripts\logs C:\Users\Todd\source\repos\MyProject\logs[1]
Enter the number of the folder to use [default = 1]:
I've spent 2 days, racking my brain over this and I'm completely stumped! Someone please save me!
Powershell Version: 5.1.26100.7019

$(...)in$($i+1)to evaluate that sub-expression, you're just missing it again in$uniqueLogFolders[$i]. powershell isn't able to tell you want to actually evaluate that indexing expression instead of using literal brackets in your string without it ;)