March 18, 2016 at 1:10 pm
Hello All,
I have a requirement to pump the data from .txt file into SQL table. I was able to do this in the past. but this time i have a problem in the data format.
Below is the sample of data format in text file.
ID, Active, User, Client, Machine, StartTime, Duration, KernelTime, UserTime
306287760, active, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.004, 0.000, 0.000
306287758, netwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.041, 0.000, 0.000
306287757, netwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.046, 0.000, 0.000
306287755, netwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.050, 0.000, 0.000
306287753, authwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.054, 0.000, 0.015
306287752, netwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.085, 0.000, 0.000
306287751, netwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.121, 0.000, 0.000
306287746, authwait, <unknown>, <unknown>, <unknown>, 12:07:13, 0:00:00.126, 0.000, 0.000
As you can see, the data is delimited by ,
it has 9 columns in this data format. I just need to pump the above data in SQL table using powershell. (I know how to pump the data into SQL from powershell. I need help to parse the above data which delimited by ,)
March 18, 2016 at 2:50 pm
No access to a computer at the moment, however, I believe that this can be achieved by string.Split and trimming the results.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 18, 2016 at 3:08 pm
I'd want the data to be read in below example command.
Get-Data | select ID, Active, User,Client,Machine, StartTime, Duration, KernelTime, UserTime
March 18, 2016 at 4:01 pm
I got it working. we can archive this thread. Thanks a lot
foreach ($line in $ReturnString)
{
$array = @()
if ($line -notmatch "ID, Active, User, Client, Machine, StartTime, Duration, KernelTime, UserTime")
{ $ProcID, $Active, $User, $Client, $Machine, $StartTime, $Duration, $KernelTime, $UserTime= $line.split(",",9) }
March 18, 2016 at 5:02 pm
Thanks for posting your solution.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
March 19, 2016 at 12:55 pm
Mac1986 (3/18/2016)
I got it working. we can archive this thread. Thanks a lotforeach ($line in $ReturnString)
{
$array = @()
if ($line -notmatch "ID, Active, User, Client, Machine, StartTime, Duration, KernelTime, UserTime")
{ $ProcID, $Active, $User, $Client, $Machine, $StartTime, $Duration, $KernelTime, $UserTime= $line.split(",",9) }
Why would you use PowerShell for such a thing? Why not just use BULK INSERT?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply