-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path检查Windows能量效率和电池使用时间问题.ps1
94 lines (63 loc) · 2 KB
/
检查Windows能量效率和电池使用时间问题.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
#
# 检查Windows设备电池使用并在桌面生成报告
#
param(
[switch]$IsRunAsAdmin = $false
)
# Get our script path
$ScriptPath = (Get-Variable MyInvocation).Value.MyCommand.Path
function LaunchElevated
{
#设置参数
$RelaunchArgs = '-ExecutionPolicy Unrestricted -file "' + $ScriptPath + '" -IsRunAsAdmin'
# Launch the process and wait for it to finish
try
{
$AdminProcess = Start-Process "$PsHome\PowerShell.exe" -Verb RunAs -ArgumentList $RelaunchArgs -PassThru
}
catch
{
$Error[0] # 输出错误
exit 1
}
Start-Sleep -Seconds 3
}
function DoElevatedOperations
{
cd $desktoppath
write-Host "正在 分析系统中常见的能量效率和电池使用时间问题 ..."
POWERCFG /ENERGY
write-Host "正在 生成电池使用情况的报告 ..."
POWERCFG /BATTERYREPORT
write-Host "正在 生成诊断连接待机报告 ..."
POWERCFG /SLEEPSTUDY
}
function DoStandardOperations
{
Write-Host "运行此脚本需要管理员权限,请通过权限!" -ForegroundColor Red
write-Host "按Enter 开始检查"
pause
LaunchElevated
}
#
#主脚本入口
#
$sfs=Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
$desktoppath = $sfs.Desktop
write-Host "=========================================================================="
write-Host "==欢迎使用电源检查脚本。 =="
write-Host "==此脚本用于检查Windows设备电池使用并在桌面生成报告。 =="
write-Host "==生成报告需要一段时间,请等待报告完成后再操作,以免影响结果。 =="
write-Host "=========================================================================="
write-Host
write-Host "结果将保存到以下位置"
write-Host $desktoppath
if ($IsRunAsAdmin)
{
DoElevatedOperations
}
else
{
DoStandardOperations
}
write-Host "完成"