-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathbatt.ps1
100 lines (84 loc) · 3.19 KB
/
batt.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
# PowerShell Script to Assess Laptop Battery Efficiency
# Function to Get Battery Information
function Get-BatteryInfo {
$battery = Get-CimInstance -ClassName Win32_Battery
if ($battery) {
$batteryStatus = switch ($battery.BatteryStatus) {
1 { "Discharging" }
2 { "Charging" }
3 { "Fully Charged" }
default { "Unknown" }
}
return @{
"Charge Percentage" = "$($battery.EstimatedChargeRemaining)%"
"Charging Status" = $batteryStatus
"Design Capacity (mWh)" = $battery.DesignCapacity
"Full Charge Capacity (mWh)" = $battery.FullChargeCapacity
"Battery Health (%)" = "{0:N2}" -f (($battery.FullChargeCapacity / $battery.DesignCapacity) * 100)
}
} else {
return @{
"Battery Info" = "No battery detected."
}
}
}
# Function to Get Screen Brightness
function Get-ScreenBrightness {
$brightness = (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightness).CurrentBrightness
return "$brightness%"
}
# Function to Get CPU Information
function Get-CPUInfo {
$cpu = Get-CimInstance -ClassName Win32_Processor
$currentClock = $cpu.CurrentClockSpeed
$maxClock = $cpu.MaxClockSpeed
$throttling = if ($currentClock -lt ($maxClock * 0.95)) { "Yes" } else { "No" }
return @{
"Current CPU Frequency (MHz)" = "$currentClock MHz"
"Max CPU Frequency (MHz)" = "$maxClock MHz"
"CPU Throttling Active" = $throttling
}
}
# Function to Get Power Plan
function Get-PowerPlan {
$powerPlan = powercfg /getactivescheme
if ($powerPlan) {
return ($powerPlan -split ': ')[1]
} else {
return "Unknown"
}
}
# Function to Get System Uptime
function Get-SystemUptime {
$uptime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
$uptimeSpan = (Get-Date) - $uptime
return $uptimeSpan.ToString("dd\.hh\:mm\:ss")
}
# Function to Get Top Power-Consuming Processes
function Get-TopProcesses {
# Requires PowerShell 5.1 or later
$processes = Get-Process | Sort-Object -Property @{Expression={$_.PM + $_.WS}} -Descending | Select-Object -First 5 |
Select-Object Name, @{Name="Memory (MB)";Expression={[math]::round($_.PM / 1MB,2)}}, @{Name="Handles";Expression={$_.Handles}}
return $processes
}
# Collect All Information
$batteryInfo = Get-BatteryInfo
$brightness = Get-ScreenBrightness
$cpuInfo = Get-CPUInfo
$powerPlan = Get-PowerPlan
$uptime = Get-SystemUptime
$topProcesses = Get-TopProcesses
# Display Summary
Write-Output "===== Laptop Battery Efficiency Report =====`n"
Write-Output ">> Battery Information:"
$batteryInfo.GetEnumerator() | ForEach-Object { Write-Output " $_.Key : $_.Value" }
Write-Output ""
Write-Output ">> Screen Brightness: $brightness`n"
Write-Output ">> CPU Information:"
$cpuInfo.GetEnumerator() | ForEach-Object { Write-Output " $_.Key : $_.Value" }
Write-Output ""
Write-Output ">> Power Plan: $powerPlan`n"
Write-Output ">> System Uptime: $uptime`n"
Write-Output ">> Top 5 Power-Consuming Processes:"
$topProcesses | Format-Table -AutoSize
Write-Output "`n============================================="