Solved

collect the statistics for the execution of powershell scripts

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

738 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