Open BinaryInk opened 5 years ago
Thanks for opening an issue @BinaryInk.
Can you please provide your environment information. The easiest way is by pasting this into your Integrated Console:
& {"### VSCode version: $(code -v)"; "`n### VSCode extensions:`n$(code --list-extensions --show-versions | Out-String)"; "`n### PSES version: $($pseditor.EditorServicesVersion)"; "`n### PowerShell version:`n$($PSVersionTable | Out-String)"}
Can you also tell us where the script is located (is it on the file system, a new folder, or put directly into the terminal) and how you executed it (did you press F5 for example?)
Ah I think I have a way to reproduce this behaviour:
If you press the up key, this gets put into PSReadLine properly and it all works.
F5 seems to do this as well...
Nailed it!
Sorry, sent that out before I left work for the day. I was using the highlight and “run selection” (F8) method as you found out, didn’t think to mention it in my report, my bad!
I was just using VSCode as a scratch pad, so no saved file, just in memory.
I can provide environment information tomorrow if it is still needed.
From: Robert Holt notifications@github.com Sent: Wednesday, April 3, 2019 8:00 PM To: PowerShell/vscode-powershell vscode-powershell@noreply.github.com Cc: BinaryInk brady.greenwood@live.com; Mention mention@noreply.github.com Subject: Re: [PowerShell/vscode-powershell] Integrated PowerShell -- Nested ForEach-Object Failing to Concatenate Strings (#1846)
Ah I think I have a way to reproduce this behaviour:
If you press the up key, this gets put into PSReadLine properly and it all works.
F5 seems to do this as well...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/PowerShell/vscode-powershell/issues/1846#issuecomment-479710436, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALft_tUKycyXV_wu0zeU3GAOCpAACLjGks5vdU6QgaJpZM4cbms-.
If F8
just ran the code though PSReadLine everything would work right? :)
I found this because I was looking to see if anyone suggested that yet because that would then cause the 'selected' code to be highlighted in the terminal.
Interesting, 1 change makes it work correctly, instead of the string split()
method, use the unary -split
operator:
$SearchBaseSuffix = 'ou=Workstations,ou=Machines in Production,dc=xxxx,dc=xxx'
$Departments = -split 'Alpha
Beta
Gamma
Zulu'
$OS = 'Windows 7','Windows 10'
$FormFactors = 'Convertibles','Laptops','Desktops'
$Departments | % {
$currDept = $_
Write-Host $currDept
$OS | % {
$currOS = $_
$FormFactors | % {
$currForm = $_
write-host "ou=$currDept,ou=$currForm,ou=$currOS,$SearchBaseSuffix"
# Get-ADComputer -Filter * -Prop 'Description' -SearchBase "ou=$$currDept,ou=$currForm,ou=$currOS,$SearchBaseSuffix" | ft
}
}
}
Ah, its caused because, at least on Windows, F8 copies `r`n
on each line, but when PSReadLine replays it, the line ends are just `n
. The string Split()
method with an operand of "`n"
is passing the extra `r
through.
Realizing that its an issue of `r`n
line endings. this can be reproduced in an actual full powershell session, storing the sample script in a normal Windows file with CRLF endings.
So this is not an issue of the PowerShell extension, but a shortfall in the script to be able to handle different conditions. The best option is probably something along the lines of building the array with separated string elements, or using the -split
operator with '\r?\n'
or '\s+'
for the delimiter pattern.
… or add the .trim()
method to the $Departments
reference ...
That's a really great investigation, thanks @msftrncs!
Issue Type: Bug
Simply put, it's not putting in $currDept (from the first ForEach-Object loop) in the string as expected, except for the last pass. Code and Outputs below.
CODE---------------------
OUTPUTS------------
Integrated Powershell Output (Incorrect):
Expected Output (Tested, Confirmed in a 'regular' PowerShell session within Code and in a separate PowerShell terminal):
Extension version: 1.12.0 VS Code version: Code 1.32.3 (a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4, 2019-03-14T23:43:35.476Z) OS version: Windows_NT x64 10.0.17763
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled| |Memory (System)|7.91GB (1.91GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|