PoshCode Archive  Artifact Content

Artifact 6277ccbfe5adc85a2cee257d8508ab1342fc4570b5c51f0c087270bddad2e364:

  • File Repeating-job-boot.ps1 — part of check-in [fa76f3973e] at 2018-06-10 13:54:17 on branch trunk — A snippet which will setup a job that repeats every 5 minutes at boot time. (user: GodEater size: 1565)

# encoding: utf-8
# api: powershell
# title: Repeating job @ boot
# description: A snippet which will setup a job that repeats every 5 minutes at boot time.
# version: 0.1
# type: script
# author: GodEater
# license: CC0
# x-poshcode-id: 5375
# x-archived: 2015-05-05T01:37:03
# x-published: 2015-08-20T19:48:00
#
# Somewhat hacky. The job in question updates your DuckDNS IP address, assuming
# you have one.
#
## DuckDNS Powershell
[scriptblock]$UpdateDuckDns = {
    $Encoding = [System.Text.Encoding]::UTF8;
    $duckdns_url = "https://www.duckdns.org/update?domains=YOUR_DOMAIN&token=YOUR_TOKEN&ip=";

    $HTTP_Response = Invoke-WebRequest -Uri $duckdns_url;
    $Text_Response = $Encoding.GetString($HTTP_Response.Content);

    if($Text_Response -ne 'OK'){
        Write-EventLog –LogName Application –Source "DuckDNS Updater" –EntryType Information –EventID 1 –Message "This is a test message.";
    }
}

[scriptblock]$SetupRepeatingJob = {
    $RepeatTimeSpan = New-TimeSpan -Minutes 5;
    $DurationTimeSpan = New-TimeSpan -Days 1000;
    $At = $(Get-Date) + $RepeatTimeSpan;
    $UpdateTrigger = New-ScheduledTaskTrigger -Once -At $At -RepetitionInterval $TimeSpan -RepetitionDuration $DurationTimeSpan;
    Register-ScheduledJob -Name RunDuckDnsUpdate -ScriptBlock $UpdateDuckDns -Trigger $UpdateTrigger;
}

New-EventLog  –LogName Application –Source "DuckDNS Updater"
$StartTrigger = New-JobTrigger -AtStartup
Register-ScheduledJob -Name StartDuckDnsJob -ScriptBlock $SetupRepeatingJob -Trigger $StartTrigger