How to read powershell script file from log parser and save data in sql using c#?


Bascially,LogParser is used to read IIS logs.We upload one log file to log parser, select query and we get results of query like :user agent,ip address(basically hits to particular url).That query is PS(PowerShell Script) file.

Any idea how to read that PS file and save output of that query to db?


Asked by:- SnehalSawant
0
: 2529 At:- 11/19/2018 8:32:03 AM
C# SQL powershell script







1 Answers
profileImage Answered by:- jaya

As you have mentioned, you have powershell scripts to get logs, then you can run Powershell script using C#, and get result as List in C# then save it into database, here is the procedure step by step:

  1. Run the PS script using C#
  2. Get Result as List<SomeModel>
  3. Loop the above List and save data into SQL server database table as usual

https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/ (Run powershell script using C#)

https://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C (Run powershell script using C#)

https://stackoverflow.com/questions/27927484/get-powershell-result-into-c-sharp-list (Get Powershell result as List)

I think above links, should solve your issue.

1
At:- 11/19/2018 11:01:46 AM Updated at:- 11/19/2018 11:03:27 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use