-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGet-BatteryReport.ps1
118 lines (80 loc) · 3.53 KB
/
Get-BatteryReport.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<#
.SYNOPSIS
This cmdlet is used to get a battery report for a local or remote device
.DESCRIPTION
Generate an HTML report on the battery of a local or remote Windows Device
.PARAMETER ComputerName
This parameter is used to define the name of a remote computer you want battery information from
.PARAMETER Path
This parameter indicates the location to save the HTML report. The default location is $env:USERPROFILE\Documents\BatteryReport.html
.PARAMETER UseSSL
This parameter indicates that you when communicating with a remote device you want to use WinRM over HTTPS instead of WinRM
.EXAMPLE
Get-BatteryReport -Path C:\Users\user\Documents\BatteryReport.html
# This example saves the battery report for the local machine to $env:USERPROFILE\Documents\BatteryReport.html
.EXAMPLE
Get-BatteryReport -ComputerName Laptop01.domain.com -Path $env:USERPROFILE\Documents\BatteryReport.html -UseSSL
# This examples saves the battery report for remote device Laptop01.domain.com to \\$env:COMPUTERNAME\C$\Users\user\Documents\BatteryReport.html. This communication happens using WinRM over HTTPS
.EXAMPLE
Get-BatteryReport
# This example saves the battery report for the local machine to $env:USERPROFILE\Documents\BatteryReport.html
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: [email protected]
.INPUTS
None
.OUTPUTS
None
.LINK
https://osbornepro.com
https://writeups.osbornepro.com
https://btpssecpack.osbornepro.com
https://github.com/OsbornePro
https://gitlab.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
https://www.hackthebox.eu/profile/52286
#>
Function Get-BatteryReport {
[CmdletBinding(DefaultParameterSetName='Local')]
param(
[Parameter(
ParameterSetName='Remote',
Mandatory=$True,
ValueFromPipeline=$False,
HelpMessage="`n[H] Enter the computer name you want to generate a battery report on. Separate multiple values with a comma. `n[E] EXAMPLE: Laptop01.domain.com")] # End Parameter
[String[]]$ComputerName,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[ValidateScript({($_ -like "*.html") -or ($_ -like "*.htm")})]
[String]$Path = "$env:USERPROFILE\Documents\BatteryReport.html",
[Parameter(
ParameterSetName='Remote',
Mandatory=$False,
ValueFromPipeline=$False)] # End Parameter
[Switch][Bool]$UseSSL
) # End param
Switch ($PsCmdlet.ParameterSetName) {
'Remote' {
$Bool = $False
If ($UseSSL.IsPresent) {
Write-Verbose "WinRM over HTTPS communication will be used to execute command"
$Bool = $True
} # End If
ForEach ($C in $ComputerName) {
Write-Verbose "Obtaining battery report from $C and saving it to $Path"
Invoke-Command -HideComputerName $C -ArgumentList $Path -UseSSL:$Bool -ScriptBlock {
cmd /c powercfg /batteryreport /output $Args[0]
} # End ScriptBlock
} # End ForEach
} # End Switch Remote
'Local' {
Write-Verbose "Obtaining battery report from $env:COMPUTERNAME and saving it to $Path"
cmd /c powercfg /batteryreport /output $Path
} # End Switch Local
} # End Switch
} # End Function Get-BatteryReport