From 9f926a0322301a8f500280b5e444b197d97e0ed6 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 23 Feb 2024 11:49:12 -0500 Subject: [PATCH] initial commit --- Create-BatteryReport.ps1 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Create-BatteryReport.ps1 diff --git a/Create-BatteryReport.ps1 b/Create-BatteryReport.ps1 new file mode 100644 index 0000000..64a0ae6 --- /dev/null +++ b/Create-BatteryReport.ps1 @@ -0,0 +1,23 @@ +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' + +# 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 }