-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.ps1
More file actions
86 lines (64 loc) · 2.06 KB
/
Copy pathProcess.ps1
File metadata and controls
86 lines (64 loc) · 2.06 KB
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
Write-Host""
Write-Host "Top 5 most CPU used program `n" -ForegroundColor Green
Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 5
# CPU usage total (en %)
# -----------------------------
$cpuLoad = (Get-Counter).CounterSamples |
Where-Object { $_.Path -match "processeur\(_total\).*temps processeur" } |
Select-Object -ExpandProperty CookedValue
$cpuLoad = [math]::Round($cpuLoad, 2)
# -----------------------------
# RAM usage (en %)
# -----------------------------
$os = Get-CimInstance Win32_OperatingSystem
$ramTotal = $os.TotalVisibleMemorySize * 1KB
$ramFree = $os.FreePhysicalMemory * 1KB
$ramUsedPercent = [math]::Round((($ramTotal - $ramFree) / $ramTotal) * 100, 2)
# -----------------------------
# Affichage couleur
# -----------------------------
function Show-Loading {
param (
[string]$Label,
[int]$Value
)
if ($Value -lt 60) {
$color = "Green"
}
elseif ($Value -lt 85) {
$color = "Yellow"
}
else {
$color = "Red"
}
Write-Host ("{0,-9}= {1} %" -f $Label, $Value) -ForegroundColor $color
}
Write-Host""
# -----------------------------
# Cpu and Ram used
# -----------------------------
Show-Loading -Label "Cpu used" -Value $cpuLoad
Show-Loading -Label "Ram Used" -Value $ramUsedPercent
Write-Host""
# -----------------------------
# IPV4 pc and IPV4 gateway
# -----------------------------
$iface = Get-NetRoute -DestinationPrefix "0.0.0.0/0" |
Sort-Object RouteMetric |
Select-Object -First 1
$ip = Get-NetIPAddress -InterfaceIndex $iface.InterfaceIndex -AddressFamily IPv4 |
Select-Object -ExpandProperty IPAddress
$gw = $iface.NextHop
Write-Host "IPv4 address : $ip" -ForegroundColor Blue
Write-Host "IPv4 gateway : $gw" -ForegroundColor Blue
# -----------------------------
# Test DNS
# -----------------------------
Write-Host""
if (Test-Connection 8.8.8.8 -Count 1 -Quiet) {
Write-Host "Internet: OK" -ForegroundColor Green
} else {
Write-Host "Internet: KO" -ForegroundColor Red
}
Write-Host""
(Get-Date).DateTime