-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ps1
36 lines (26 loc) · 1019 Bytes
/
script.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
# PowerShell script to check the system performance
$startTime = Get-Date
$filePath = '.\ServerMonitor.csv'
if (!(Test-Path $filePath -PathType Leaf))
{
$table=@"
Server Name,Timestamp,Memory Usage (in %),CPU Usage (in %),(C:/) Total Capacity,(C:/) Used Capacity (in %),(C:/)Free Capacity (in %),(E:/) Total Capacity,(E:/) Used Capacity (in %),(E:/)Free Capacity (in %),(F:/) Total Capacity,(F:/) Used Capacity (in %),(F:/)Free Capacity (in %)
"@
}
$result = ""
$RAM = Get-WmiObject -ClassWin32_OperatingSystem -ErrorAction Stop
if (-not$?)
{
throw $_
}
[int]$RAMtotal =$RAM.TotalVisibleMemorySize
$RAMAvail =$RAM.FreePhysicalMemory
$RAMpercent =[Math]::Round(($RAMtotal- $RAMAvail) * 100/$RAMtotal)
$CPU = Get-WmiObject win32_processor| Measure-Object-property LoadPercentage-Average -ErrorActionStop |Select Average
if (-not$?)
{
throw $_
}
$CPUAverage =$CPU.Average
$resultStr =$resultStr +$env:COMPUTERNAME+","+$startTime+","+$RAMpercent+","+$CPUAverage
Add-Content $filePath $result