troubleshooting Question

powershell joinging strings without a space

Avatar of Dead_Eyes
Dead_EyesFlag for United Kingdom of Great Britain and Northern Ireland asked on
13 Comments1 Solution221 ViewsLast Modified:
Hi, I am still learning PowerShell and attempting to resolve a problem I found when exploring the functionality of the ForEach-Object Cmdlet. When I attempt to join the 2 variables a space appears in between them and I can't seem to get rid of it no matter what I try. I think its something to do with the Output field separator but after trying several different tactics to change it I am at a loss. I have noticed if I use a txt file instead of a .csv & Get-Content the problem does not occur but using .txt files would limit the use's I am envisioning for ForEach-Object. Can anyone offer a solution preferably with an explanation of why and how to manipulate variables in the loop? thanks in advance

$var1 = Import-Csv -Path D:\Book1.csv
$Ending = ""
$Var1 | ForEach-Object {
Write-Host $_.Name,$Ending
Neil Russell
Solution Development Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros