Solved

collect the statistics for the execution of powershell scripts

Posted on 2013-05-13
1
355 Views
Last Modified: 2013-05-14
Hello,

How to collect the statistics for the execution of powershell scripts in a table in SQL SERVER (date, name of the script execution time) data?
Do you have any sample scripts or command?

thank you

Regards
0
Comment
Question by:bibi92
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39163230
You will need to have a "wrapper" script, which takes the script name as a parameter, then execute it with measure-command, and construct an insert statement with the result.
function measure-script ([String] $scriptname)
{
  $connstr = "server=MSSQLserver; database=Stats; Integrated Security=SSPI"
  $dt = get-date
  $mo = measure-command { & "$scriptname" }
  System.Data.SqlClient.SqlCommand(
      "insert into psscriptstats (scriptname, starttime, exectime) values ('$scriptname', '$dt', $($mo.milliseconds))",
      new-object System.Data.SqlClient.SqlConnection($connstr)
  )
}

Open in new window

is a minimalistic approach (untested).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question