|
|
@@ -196,12 +196,12 @@ Add-Type -Namespace Native -Name Power -MemberDefinition @'
|
|
|
|
public static extern uint SetThreadExecutionState(uint esFlags);
|
|
|
|
public static extern uint SetThreadExecutionState(uint esFlags);
|
|
|
|
'@
|
|
|
|
'@
|
|
|
|
|
|
|
|
|
|
|
|
$ES_CONTINUOUS = 0x80000000
|
|
|
|
$ES_CONTINUOUS = [Convert]::ToUInt32('80000000', 16)
|
|
|
|
$ES_SYSTEM_REQUIRED = 0x00000001
|
|
|
|
$ES_SYSTEM_REQUIRED = [Convert]::ToUInt32('00000001', 16)
|
|
|
|
$ES_DISPLAY_REQUIRED = 0x00000002
|
|
|
|
$ES_DISPLAY_REQUIRED = [Convert]::ToUInt32('00000002', 16)
|
|
|
|
|
|
|
|
|
|
|
|
function Set-StayAwake {
|
|
|
|
function Set-StayAwake {
|
|
|
|
[Native.Power]::SetThreadExecutionState($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED -bor $ES_DISPLAY_REQUIRED) | Out-Null
|
|
|
|
[Native.Power]::SetThreadExecutionState([uint32]($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED -bor $ES_DISPLAY_REQUIRED)) | Out-Null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function Clear-StayAwake {
|
|
|
|
function Clear-StayAwake {
|
|
|
@@ -283,6 +283,19 @@ function Get-BatteryInfo {
|
|
|
|
|
|
|
|
|
|
|
|
#region Main
|
|
|
|
#region Main
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
# Validate/prepare the log path up front so a bad path fails fast, before power settings or
|
|
|
|
|
|
|
|
# the CPU load are touched. Falls back to the script folder if the requested location is invalid.
|
|
|
|
|
|
|
|
$logDir = Split-Path -Path $LogPath -Parent
|
|
|
|
|
|
|
|
if ($logDir -and -not (Test-Path -Path $logDir)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
$fallbackPath = Join-Path -Path $PSScriptRoot -ChildPath (Split-Path -Path $LogPath -Leaf)
|
|
|
|
|
|
|
|
Write-Warning "Could not create log directory '$logDir' ($($_.Exception.Message)). Falling back to '$fallbackPath'."
|
|
|
|
|
|
|
|
$LogPath = $fallbackPath
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (-not $SkipPowerSettingsChanges) {
|
|
|
|
if (-not $SkipPowerSettingsChanges) {
|
|
|
|
Set-PowerSettingsForBatteryTest
|
|
|
|
Set-PowerSettingsForBatteryTest
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@@ -295,9 +308,6 @@ try {
|
|
|
|
Write-Host "Starting synthetic CPU load targeting ~$TargetLoadPercent% across $cores logical processors..." -ForegroundColor Cyan
|
|
|
|
Write-Host "Starting synthetic CPU load targeting ~$TargetLoadPercent% across $cores logical processors..." -ForegroundColor Cyan
|
|
|
|
$loadJobs = Start-CpuLoad -Percent $TargetLoadPercent -Cores $cores
|
|
|
|
$loadJobs = Start-CpuLoad -Percent $TargetLoadPercent -Cores $cores
|
|
|
|
|
|
|
|
|
|
|
|
if (-not (Test-Path (Split-Path -Path $LogPath -Parent))) {
|
|
|
|
|
|
|
|
New-Item -ItemType Directory -Path (Split-Path -Path $LogPath -Parent) -Force | Out-Null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
"Timestamp,PercentRemaining,Status,Charging,EstimatedRunTimeMinutes" | Out-File -FilePath $LogPath -Encoding UTF8
|
|
|
|
"Timestamp,PercentRemaining,Status,Charging,EstimatedRunTimeMinutes" | Out-File -FilePath $LogPath -Encoding UTF8
|
|
|
|
|
|
|
|
|
|
|
|
Write-Host "Logging battery status every $SampleIntervalSeconds s to $LogPath" -ForegroundColor Cyan
|
|
|
|
Write-Host "Logging battery status every $SampleIntervalSeconds s to $LogPath" -ForegroundColor Cyan
|
|
|
|