SQLServerCentral.com / Programming / Powershell / Concat hard value to each row of Hash Table / Latest PostsInstantForum.NET v99.99.99SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comFri, 09 Dec 2016 18:39:24 GMT20RE: Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxThat works wonderfully. Thanks.Mon, 21 Apr 2014 07:08:31 GMTBrandie TarvinRE: Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxI've only used the WebClient class to download data, not upload. Maybe someone else will be able to answer. But reading the docs it looks like that method requires a file. If you wanted to try streaming it you might look into the OpenWrite method.Since you said you're working with many rows and columns instead of loading everything into an array you can just write to a file as you go.Here's a modification of my first answer.[code]$OutFile = 'FileName.txt'Foreach ($line In Get-Content SampleData.txt) { "{0}{1}{0}`n" -F $bound, $line | Out-File -FilePath $OutFile -Append}[/code]Fri, 18 Apr 2014 11:54:01 GMTbruce 1565RE: Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxActually, it just occurs to me... Can I use [url=http://msdn.microsoft.com/en-us/library/system.net.webclient.uploadfile(v=vs.110).aspx]WebClient.UploadFile method[/url] with this code? Do I have to create a physical file for this or can I just stream it from Powershell to the HTTPS server?Fri, 18 Apr 2014 05:24:41 GMTBrandie TarvinRE: Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxBRILLIANT!That's exactly what I needed. I thought I had to load the file into Powershell before playing with it (ala a temp table).Thank you. Now I just have to figure out my headers and the send method. @=)Fri, 18 Apr 2014 04:32:18 GMTBrandie TarvinRE: Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxWould something like this work or do you need the hashtable?[code]$bound = '------=_12253dsfae4654'Foreach ($line In Get-Content SampleData.txt) { $test += "{0}{1}{2}`n" -F $bound, $line, $bound }$test[/code]Thu, 17 Apr 2014 15:11:27 GMTbruce 1565Concat hard value to each row of Hash Tablehttp://www.sqlservercentral.com/Forums/Topic1562838-1351-1.aspxI'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.Thu, 17 Apr 2014 13:46:48 GMTBrandie Tarvin