[CmdletBinding()] param( [string]$OutDir = '.', [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $OutDir -PathType Container)) { New-Item -ItemType Directory -Path $OutDir | Out-Null } $html = Join-Path $OutDir 'battery-report.html' & powercfg.exe /batteryreport /output $html 2>&1 | Out-Null if (Test-Path -LiteralPath $html) { Write-Host "HTML-отчёт батареи: $html" } else { Write-Warning 'powercfg не создал battery-report.html.' } $battery = @(Get-CimInstance -ClassName Win32_Battery -ErrorAction SilentlyContinue | Select-Object Name, EstimatedChargeRemaining, BatteryStatus, EstimatedRunTime, DesignCapacity, FullChargeCapacity) if ($battery.Count -gt 0) { Write-Host 'Батареи:' $battery | Format-Table -AutoSize } else { Write-Host 'Батарея не найдена. Для настольного компьютера это нормально.' } $active = (& powercfg.exe /getactivescheme 2>&1 | Out-String).Trim() $plans = (& powercfg.exe /list 2>&1 | Out-String).Trim() $sleep = (& powercfg.exe /query SCHEME_CURRENT SUB_SLEEP 2>&1 | Out-String).Trim() Write-Host '' Write-Host "Активная схема: $active" Write-Host 'Схемы питания:' Write-Host $plans $sleepFile = Join-Path $OutDir 'power-sleep.txt' Set-Content -LiteralPath $sleepFile -Value $sleep -Encoding UTF8 Write-Host "Параметры сна: $sleepFile" if ($Csv) { $parent = Split-Path -Parent $Csv if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent | Out-Null } $battery | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Сводка по батарее: $Csv" } Write-Host 'Настройки питания не изменялись.'