-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-07-Part1-MonitorPerformanceSaveToHTML.ps1
68 lines (54 loc) · 1.66 KB
/
06-07-Part1-MonitorPerformanceSaveToHTML.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
#FERDIG
$rootpath = "C:\Users\burmo\Documents\Oblig7 og senere\dcst1005"
$scriptBlock = {
# Capturing performance data
$data = @()
$data += Get-Counter '\Processor(_Total)\% Processor Time' | ForEach-Object { $_.CounterSamples }
$data += Get-Counter '\Memory\% Committed Bytes In Use' | ForEach-Object { $_.CounterSamples }
$data += Get-Counter '\Memory\Available MBytes' | ForEach-Object { $_.CounterSamples }
$data += Get-Counter '\LogicalDisk(*)\% Disk Time' | ForEach-Object { $_.CounterSamples }
$data += Get-Counter '\Network Interface(*)\Bytes Total/sec' | ForEach-Object { $_.CounterSamples }
$data
}
# Duration and interval settings
$duration = 20 #24 * 60 # 24 hours in minutes
$interval = 1 # Interval in seconds
$startTime = Get-Date
# Loop to collect data every interval for the duration of 24 hours
$results = while ((New-TimeSpan -Start $startTime).TotalMinutes -lt $duration) {
Invoke-Command -ComputerName dc1,srv1 -ScriptBlock $scriptBlock
Start-Sleep -Seconds ($interval)
}
$html = @"
<html>
<head>
<title>Performance Report</title>
</head>
<body>
<h1>Performance Report</h1>
<table border="1">
<tr>
<th>Time</th>
<th>Counter</th>
<th>Value</th>
</tr>
"@
foreach ($result in $results) {
foreach ($sample in $result) {
$html += @"
<tr>
<td>$($sample.Timestamp)</td>
<td>$($sample.Path)</td>
<td>$($sample.CookedValue)</td>
</tr>
"@
}
}
$html += @"
</table>
</body>
</html>
"@
# Save HTML to file
"performanceReport.html"
$html | Out-File -FilePath "$rootpath\performanceReport.html" -Force