2024-02-23 11:49:12 -05:00
|
|
|
Function Get-LongDate {
|
|
|
|
|
Return $(Get-Date -Format "yyyyMMdd")
|
|
|
|
|
}
|
|
|
|
|
$OutputDirectory = "${Env:PROGRAMDATA}\Emberkom\Output"
|
|
|
|
|
|
|
|
|
|
# Exit this script if the current device doesn't have a built-in battery
|
|
|
|
|
If ( $null -eq (Get-CimInstance -ClassName Win32_Battery -ErrorAction SilentlyContinue) ) { Exit }
|
|
|
|
|
|
|
|
|
|
# Define file paths
|
|
|
|
|
$Today = Get-LongDate
|
|
|
|
|
$ReportPathNoExt = "${OutputDirectory}\batteryreport_${Env:COMPUTERNAME}_${Today}"
|
|
|
|
|
$HtmlReportPath = $ReportPathNoExt + '.html'
|
|
|
|
|
$XmlReportPath = $ReportPathNoExt + '.xml'
|
|
|
|
|
|
2024-02-23 11:52:57 -05:00
|
|
|
# Delete reports if they already exist
|
|
|
|
|
If ( Test-Path $XmlReportPath ) { Remove-Item -Path $XmlReportPath -Force }
|
|
|
|
|
If ( Test-Path $HtmlReportPath ) { Remove-Item -Path $HtmlReportPath -Force }
|
|
|
|
|
|
2024-02-23 11:49:12 -05:00
|
|
|
# Generate the XML report
|
|
|
|
|
Write-Output "Generating XML battery report: ${XmlReportPath}"
|
|
|
|
|
Try { Start-Process "powercfg.exe" -ArgumentList "/batteryreport /output ""${XmlReportPath}"" /xml" -Wait }
|
|
|
|
|
Catch { Write-Error $_.Exception.Message }
|
|
|
|
|
|
|
|
|
|
# Convert XML report to HTML
|
|
|
|
|
Write-Output "Generating HTML battery report: ${HtmlReportPath}"
|
|
|
|
|
Try { Start-Process "powercfg.exe" -ArgumentList "/batteryreport /transformxml ""${XmlReportPath}"" /output ""${HtmlReportPath}""" -Wait }
|
|
|
|
|
Catch { Write-Error $_.Exception.Message }
|