Skip to content

Instantly share code, notes, and snippets.

@aelxxs
Created July 1, 2022 00:03
Show Gist options
  • Select an option

  • Save aelxxs/92026f1e9837c598ff434fe819fbac70 to your computer and use it in GitHub Desktop.

Select an option

Save aelxxs/92026f1e9837c598ff434fe819fbac70 to your computer and use it in GitHub Desktop.
[Windows]: Battery status for Lanyard
# REPLACE :id with your Discord ID
# REPLACE :key with your Lanyard API Key
# TASK: run every minute
$endpoint = "https://api.lanyard.rest/v1/users/:id/kv/battery"
function Get-ChargingStatus {
return (Get-WmiObject -Class BatteryStatus -Namespace root\wmi).Charging
}
function Get-Percentage {
return (Get-WmiObject -Class Win32_Battery).EstimatedChargeRemaining
}
$body = @{
isCharging=Get-ChargingStatus;
percentage=Get-Percentage;
} | ConvertTo-Json
$auth = @{
"Authorization"=":key"
"Content-Type"="application/json"
}
Invoke-WebRequest -Uri $endpoint -Method PUT -Headers $auth -Body $body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment