Solved

collect the statistics for the execution of powershell scripts

Posted on 2013-05-13
1
341 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
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 …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now