Solved

collect the statistics for the execution of powershell scripts

Posted on 2013-05-13
1
340 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
1 Comment
 
LVL 68

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now