November 21, 2016 at 3:30 pm
Hi,
I have string with following format
$string = @'
AvgSQLCpu,AVGCpu,AVGOtherCpu
100,97,2
alertType,alertStatus,alertGenerate,alertDetails
HIGHCPU,ERROR,0,
'@
I have 2 table objects
[object] $tbl1 = New-Object Data.DataTable "tbl1"
$null=$tbl1.Columns.Add("AvgSQLCpu",[int])
$null=$tbl1.Columns.Add("AVGCpu",[Int])
$null=$tbl1.Columns.Add("AVGOtherCpu",[Int])
[object] $tbl2 = New-Object Data.DataTable "tbl2"
$null=$tbl2.Columns.Add("alertType",[string])
$null=$tbl2.Columns.Add("alertStatus",[string])
$null=$tbl2.Columns.Add("alertGenerate",[Int])
$null=$tbl2.Columns.Add("alertDetails",[string])
How do I insert
100,97,2 into tbl1
and
HIGHCPU,ERROR,0, into tbl2
Thank you
November 22, 2016 at 7:30 am
I would get the individual values as such:
$v = $string.Split(",");
This splits the values as follows:
AvgSQLCpu
AVGCpu
AVGOtherCpu
100
97
2
alertType
alertStatus
alertGenerate
alertDetails
HIGHCPU
ERROR
0
Where $v[0] is the string "AvgSQLCpu", $v[1] is the string "AVGCpu", $v[2] is the string "AVGOtherCpu" etc.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
November 22, 2016 at 8:03 am
Thanks a lot ! Good and simple!
the only problem
Where $v[4] # no comma and return 2 values
AVGOtherCpu
100
Where $v[5] # no comma and return 2 values
alertDetails
HIGHCPU
need somehow split also "end of the line"
November 22, 2016 at 8:13 am
$v = $string.Split("`n");
$x = ($v[1]).split(',')
$y = ($v[3]).split(',')
$x[0]
$x[1]
$x[2]
write-output "second dataset"
$y[0]
$y[1]
$y[2]
November 22, 2016 at 8:19 am
Thanks for posting your final solution.
(Mine worked for me but maybe copy 'n' paste lost the newline character).
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
November 22, 2016 at 8:20 am
Gary Varga (11/22/2016)
Thanks for posting your final solution.(Mine worked for me but maybe copy 'n' paste lost the newline character).
Looking at the original post I don't know how mine ever worked :blink:
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply