-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.ps1
53 lines (47 loc) · 1.57 KB
/
demo.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
# Function to print a table with colored headers
function Print-Table {
param (
[string[]]$Headers,
[string[][]]$Rows
)
# Set colors
$HeaderColor = "Red"
$RowColor = "White"
# Print headers
$HeaderLine = ""
foreach ($header in $Headers) {
$HeaderLine += "{0,-40}" -f $header
}
Write-Host $HeaderLine -ForegroundColor $HeaderColor
# Print rows
foreach ($row in $Rows) {
$RowLine = ""
foreach ($cell in $row) {
$RowLine += "{0,-40}" -f $cell
}
Write-Host $RowLine -ForegroundColor $RowColor
}
}
# Gather system statistics
$cpu = Get-WmiObject -Class Win32_Processor | Select-Object -ExpandProperty LoadPercentage
$memory = Get-WmiObject -Class Win32_OperatingSystem
$totalMemory = [math]::Round($memory.TotalVisibleMemorySize / 1MB, 2)
$freeMemory = [math]::Round($memory.FreePhysicalMemory / 1MB, 2)
$usedMemory = $totalMemory - $freeMemory
$disk = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3"
$diskStats = @()
foreach ($d in $disk) {
$diskStats += @($d.DeviceID, [math]::Round($d.Size / 1GB, 2), [math]::Round($d.FreeSpace / 1GB, 2))
}
Write-Output "-------------- System Statistics --------------"
# Create table data
$headers = @("Metric", "Value")
$rows = @(
@("CPU Usage (%)", "$cpu%"),
@("Total Memory (GB)", "$totalMemory GB"),
@("Used Memory (GB)", "$usedMemory GB"),
@("Free Memory (GB)", "$freeMemory GB"),
@("Disk $($diskStats[0]) Total (GB)", "$($diskStats[1]) GB")
)
# Print the table (test)
Print-Table -Headers $headers -Rows $rows