how to write a hash in the way it can easily be readed again?

rated by 0 users
This post has 1 Reply | 2 Followers

Top 500 Contributor
Posts 3
calli Posted: 09-08-2009 12:25 PM

Hi,

I am new to powershell and need to use hashes: to read them, to amend them, and to save them again.

I found impressive easy ways to convert string (read from files) into a hash:

$tmp = @"
          EURUSD=19000000
          USDCHF=19000000
          GBPUSD=19000000
"@

$lastDate = convertfrom-stringdata $tmp

But I haven't found any example or code snippet to write hashes into a file preferable like key=value. Is there only the long way: foreach ... write .. or does exist a 'one liner'?

Well, in powershell, what is the best way to save a hash in order to read it again?

 

Thanks a lot,

calli

Top 10 Contributor
Posts 555
Microsoft MVP
Top Contributor

well, a hash is just string data so you could pipe it to Out-File.

Or, in order to save more than one hash in a file, consider adding them to an object and writing objects to a CSV. Here is an example:

$object = 1 | Select-Object "Filename", "Hash"
$object.FileName = "bla"
$object.Hash = "bla"
$object | Export-Csv $home\result.txt
$import = Import-Csv $home\result.txt
$import.FileName
$import.Hash

Cheers, Tobias 

Page 1 of 1 (2 items) | RSS
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.