Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Adding data to a hash table

Reply
 
Old 12-27-2007   #1 (permalink)
NeilOz
Guest


 
 

Adding data to a hash table

I have imported a csv using import-csv

$clcode = import-csv $csvlocation | select clcode

$clcode results are a list of 6 digit numbers, for the next part of the
script I need to add ',' to the end of the 6 digits, I have messed around
with different methods and have been unable to figure out how to do it,
easily.

Please help
Neil

My System SpecsSystem Spec
Old 12-27-2007   #2 (permalink)
Jeff
Guest


 
 

Re: Adding data to a hash table

On Dec 28, 8:13 am, NeilOz <Nei...@xxxxxx> wrote:
Quote:

> I have imported a csv using import-csv
>
> $clcode = import-csv $csvlocation | select clcode
>
> $clcode results are a list of 6 digit numbers, for the next part of the
> script I need to add ',' to the end of the 6 digits, I have messed around
> with different methods and have been unable to figure out how to do it,
> easily.
>
> Please help
> Neil
Neil,

This should do the trick:

for ( $i = 0; $i -lt $clcode.Length; $i++ )
{
$clcode[ $i ] += ","
}

Jeff
My System SpecsSystem Spec
Old 12-27-2007   #3 (permalink)
Karl Prosser[MVP]
Guest


 
 

Re: Adding data to a hash table

import-csv creates a collection of objects with properties generated
from your columns in the csv.

so here i presume clcode is the name of that column.. then you could do
something like this

import-csv $csvlocation | foreach { $_.clcode += ',' }


NeilOz wrote:
Quote:

> I have imported a csv using import-csv
>
> $clcode = import-csv $csvlocation | select clcode
>
> $clcode results are a list of 6 digit numbers, for the next part of the
> script I need to add ',' to the end of the 6 digits, I have messed around
> with different methods and have been unable to figure out how to do it,
> easily.
>
> Please help
> Neil
My System SpecsSystem Spec
Old 12-27-2007   #4 (permalink)
Keith Hill [MVP]
Guest


 
 

Re: Adding data to a hash table

"NeilOz" <NeilOz@xxxxxx> wrote in message
news:64A62FA8-4C54-49AC-9EEC-993ABB38D334@xxxxxx
Quote:

> I have imported a csv using import-csv
>
> $clcode = import-csv $csvlocation | select clcode
>
> $clcode results are a list of 6 digit numbers, for the next part of the
> script I need to add ',' to the end of the 6 digits, I have messed around
> with different methods and have been unable to figure out how to do it,
> easily.
Try this:

$clcode = import-csv $csvlocation | select clcode | foreach
{"$($_.clcode),"}

This just uses string interpolation to convert the number into a string
followed by the comma.

--
Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Sorting a Hash Table before outputting it to html PowerShell
How to create a hash table from an array PowerShell
Passing hash table by reference PowerShell
Variable as hash table issue PowerShell
How do I read a XML file into a hash table? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46