Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Concat hard value to each row of Hash Table

$
0
0
I'm a newbie to Powershell and this one is driving me nuts. I have a document with many many rows of data and many columns for each row. I am sending this data via HTTPS post to a webserver and need to have each line prepended and appended with a "boundary". I can't seem to create a hash table with the first column of boundary, a second column blank (to be updated with Get-Content from the file), and a third column of boundary. And when I try a FOR loop to get the data prepended, the hard coded value ends up at the end of the file.I've done about 30 different iterations of code, getting errors and making changes along the way. The below code is the closest I've come to desired results:[code]$bound = '------=_12253dsfae4654'$Hash3 = @{};$Hash3 = (Get-Content .\SampleData.txt | Select -First 10 | Format-Table -Property FirstName,LastName,Location)$Hash3$Cnt2 = (Get-Content .\SampleData.txt | Measure-Object)$Counter = $Cnt2.Count$Test = $boundfor ($i=1;$i -le $Counter; $i++) { $Test = "$($Test) $($bound) $($Hash3[$i]) $($bound)" }$Test [/code]Screenshot of my results is loaded and for brevity's sake, I've created a sample data file with only 3 columns and 6 rows.Here's what I'm looking to achieve, but results do NOT have to be ordered like they are in the sample file. My only requirement is that each record have this boundary value prepended and appended to each row. [quote]------=_12253dsfae4654Mickey,Mouse,Florida------=_12253dsfae4654------=_12253dsfae4654Donald,Duck,Orlando------=_12253dsfae4654------=_12253dsfae4654Doctor,Who,Tardis------=_12253dsfae4654...etc[/quote]My Google-Fu gives me all sorts of basic help files on Hash Tables and Arrays, but nothing that helps me with concating a hard coded value to each individual line. I would appreciate any links, suggestions, etc. that you can think of.

Viewing all articles
Browse latest Browse all 467

Trending Articles