$ErrorActionPreference='Continue' $py=(Get-Command python -ErrorAction SilentlyContinue).Source if(-not $py -or $py -match 'WindowsApps'){ $py=(Get-ChildItem 'C:\Python*\python.exe','C:\Program Files\Python*\python.exe' -ErrorAction SilentlyContinue|Select-Object -First 1 -ExpandProperty FullName) } Write-Host "Python: $py" $t = Get-ScheduledTask -TaskName glances -ErrorAction SilentlyContinue if(-not $t){ $a=New-ScheduledTaskAction -Execute $py -Argument '-m glances -w --disable-webui -t 5' $tr=New-ScheduledTaskTrigger -AtStartup $pr=New-ScheduledTaskPrincipal -UserId 'SYSTEM' -RunLevel Highest Register-ScheduledTask -TaskName glances -Action $a -Trigger $tr -Principal $pr -Force | Out-Null Write-Host '已重建 glances 计划任务' } Stop-ScheduledTask -TaskName glances -ErrorAction SilentlyContinue Start-Sleep 1 Start-ScheduledTask -TaskName glances Start-Sleep 10 try{ $r=Invoke-WebRequest 'http://127.0.0.1:61208/api/4/status' -UseBasicParsing -TimeoutSec 6; Write-Host "OK glances 61208 -> $($r.StatusCode)" }catch{ Write-Host "FAIL: $($_.Exception.Message)" }