Last active
March 24, 2026 06:00
-
-
Save hunandy14/c7fa21d0e2ad88a7443e9aef3010f89c to your computer and use it in GitHub Desktop.
Windows 開機自動同步 duck dns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Register-DuckDNS { | |
| param( | |
| [Parameter(Mandatory)][string]$Domain, | |
| [Parameter(Mandatory)][string]$Token, | |
| [int]$Interval | |
| ) | |
| Get-ScheduledTask -TaskName "DuckDNS_9615e983" -ErrorAction SilentlyContinue | | |
| Unregister-ScheduledTask -Confirm:$false | |
| $url = "https://www.duckdns.org/update?domains=$Domain&token=$Token" | |
| $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -Command `"Invoke-RestMethod '$url'`"" | |
| $triggers = @(New-ScheduledTaskTrigger -AtStartup) | |
| if ($Interval) { | |
| $triggers += New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $Interval) -RepetitionDuration (New-TimeSpan -Days 9999) | |
| } | |
| $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable | |
| Register-ScheduledTask -TaskName "DuckDNS_9615e983" -Action $action -Trigger $triggers -Settings $settings -User "SYSTEM" -RunLevel Highest | |
| } | |
| function Get-DuckDNS { | |
| Get-ScheduledTask -TaskName "DuckDNS_9615e983" -ErrorAction SilentlyContinue | |
| } | |
| function Unregister-DuckDNS { | |
| Unregister-ScheduledTask -TaskName "DuckDNS_9615e983" -Confirm:$false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment