Modify each row of a CSV via powershell -
i have bunch of csv files contain info on files various machines. includes info such file hash - sha1, md5 etc.
headers *md5,sha-1,sha-256*
sample info ecfc9af8d1a6e16223e1b17ea732fa08 ,1db05a7a663a0de3b4913bf57f55e81d2b7e3663,bf74e48e2f14dcba257473fccec3e512c7283335610205e3b84cb16449e86335
my challenge how append 0x every sha-1 entry in csv file. have tried several things nil seemed work. mini problem overcome 1 time re-export info csv info has double quotes added each file hash. isn't problem in case want take these file hashes , bounce them off of sql db. why need add together 0x each entry create compatible existing hash db.
thanks in advance assistance.
import-csv of way:
import-csv .\samplehash.csv -header md5,sha1,sha256
produces output this:
md5 sha1 sha256 --- ----- ------- ecfc9af8d1a6e16223e1b17ea732fa08 1db05a7a663a0de3b4913bf57f55e81d2b7e3663 bf74e48e2f14dcba257473fccec3e512c7283335610205e3b84... ecfc9af8d1a6e16223e1b17ea732fa08 1db05a7a663a0de3b4913bf57f55e81d2b7e3663 bf74e48e2f14dcba257473fccec3e512c7283335610205e3b84...
now pipe result foreach (%) create sql string.
import-csv .\samplehash.csv -header md5,sha1,sha256 | %{ "insert hashes(md5,sha1,sha256) values('0x{0}','0x{1}','0x{2}')" -f $_.md5,$_.sha1,$_.sha256 }
now utilize strings invoke-sqlcmd or similar (depending on db system) insert rows.
powershell powershell-v3.0
No comments:
Post a Comment