-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathGet-StaExecutions_Html.ps1
130 lines (115 loc) · 4.42 KB
/
Get-StaExecutions_Html.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#Requires -Version 5.0
<#
.SYNOPSIS
Generates a report about the executions
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
Requires the library script StatisticLib.ps1
Requires Library Script ReportLibrary from the Action Pack Reporting\_LIB_
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/Statistics/_REPORTS_
.Parameter StartDate
[sr-en] Start date of the report
[sr-de] Startdatum des Reports
.Parameter EndDate
[sr-en] End date of the report
[sr-de] Endedatum des Reports
.Parameter ActionName
[sr-en] Only executions of this action
[sr-de] Nur Ausführungen dieser Aktion
.Parameter TargetName
[sr-en] Only executions on this target
[sr-de] Nur Ausführungen auf diesem Zielsystem
#>
[CmdLetBinding()]
Param(
[Parameter(HelpMessage="ASRDisplay(Date)")]
[datetime]$StartDate,
[Parameter(HelpMessage="ASRDisplay(Date)")]
[datetime]$EndDate,
[string]$ActionName,
[string]$TargetName
)
$con = $null
try{
$result = New-Object System.Collections.Generic.List[PSCustomObject]
OpenSqlConnection -SqlCon ([ref]$con)
if($null -eq $StartDate){
$StartDate = Get-Date -Year 2019 -Month 1 -Day 1
}
if($null -eq $EndDate){
$EndDate = Get-Date
}
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlDS = New-Object System.Data.DataSet
$sqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$sqlCmd.CommandText = 'GetExecutions'
$sqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure
$null = $sqlCmd.Parameters.AddWithValue('StartDate',$StartDate.Date.ToFileTimeUtc())
$null = $sqlCmd.Parameters.AddWithValue('EndDate',$EndDate.AddDays(1).Date.ToFileTimeUtc())
if($PSBoundParameters.ContainsKey('ActionName') -eq $true){
$null = $sqlCmd.Parameters.AddWithValue('Action',$ActionName)
}
if($PSBoundParameters.ContainsKey('TargetName') -eq $true){
$null = $sqlCmd.Parameters.AddWithValue('Target',$TargetName)
}
$sqlCmd.Connection = $con
$sqlAdapter.SelectCommand = $sqlCmd
$sqlAdapter.Fill($sqlDS)
[string]$action
[string]$target
[UInt64]$sumIt
if(($null -ne $sqlDS) -and ($sqlDS.Tables.Count -gt 0) -and ($sqlDS.Tables[0].Rows.Count -gt 0)){
foreach($row in $sqlDS.Tables[0].Rows){
$sumIt += ([uint64]$row['CostReduction'])
if($null -eq $row['ActionName']){
$action = ''
}
else{
$action = $row['ActionName']
}
if($null -eq $row['TargetName']){
$target = ''
}
else{
$target = $row['TargetName']
}
$result.Add([PSCustomObject] @{
'Reason' = $row['Reason']
'Cost reduction (sec)' = $row['CostReduction']
'Started' = [System.DateTime]::FromFileTimeUtc($row['Started'])
'Ended' = [System.DateTime]::FromFileTimeUtc($row['Ended'])
'Duration (sec)' = $row['Duration']
'Action' = $action
'Target' = $target
})
}
# total header line
$result.Insert(0,[PSCustomObject] @{
'Reason' = 'Total cost reduction'
'Cost reduction (sec)'= $sumIt
'Started' = ''
'Ended' = ''
'Duration (sec)' = ''
'Action' = ''
'Target' = ''
})
$sqlDS.Dispose()
}
$sqlAdapter.Dispose()
$sqlCmd.Dispose()
ConvertTo-ResultHtml -Result $result # call script library function
}
catch{
throw
}
finally{
CloseSqlConnection -SqlCon $con
}