InstallPeterDDns.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

<#PSScriptInfo
 
.VERSION 1.1
 
.GUID 2ca708fa-736f-4ed1-bf46-1400aac58e37
 
.AUTHOR Peter
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>


<#
 
.DESCRIPTION
 Installer for peter's ddns implemention client
 
#>
 
$ak = Read-Host -Prompt 'Input aliyun access key'
$sk = Read-Host -Prompt 'Input aliyun secret key'
$domain = Read-Host -Prompt 'Input your domain, like "peterzhang.top"'
$rr = Read-Host -Prompt 'Input the resource record like the "www" in "www.peterzhang.top"'

function test
{
    Trap{
        Continue
    }
    $job=Get-ScheduledJob -Name PeterDDnsUpload
    if($job -ne $null){
        echo 'Removing existed DDNS upload task...'
        $job | Unregister-ScheduledJob
    }
}
test
echo 'Installing DDNS upload task...'
$jobopt = New-ScheduledJobOption -StartIfOnBattery
Register-ScheduledJob -Name PeterDDnsUpload -ScriptBlock { C:/Windows/System32/ddns_aliyun.exe -a $ak -s $sk -d $domain -r $rr } -ScheduledJobOption $jobopt
$job=Get-ScheduledJob -Name PeterDDnsUpload

# ���ض������ļ�
echo 'Downloading DDNS client...'
Invoke-WebRequest -Uri http://ftp.peterzhang.top/ddns_aliyun.exe -OutFile C:\Windows\System32\ddns_aliyun.exe

$jobt=New-JobTrigger -Once -At (Get-Date) -RepetitionInterval '00:10:00' -RepeatIndefinitely
Add-JobTrigger -Trigger $jobt $job
#$jobt2 = New-JobTrigger -Once -At (Get-Date).AddSeconds(2)
#Add-JobTrigger -Trigger $jobt2 $job
echo 'Running test...'
C:/Windows/System32/ddns_aliyun.exe -a $ak -s $sk -d $domain -r $rr
echo 'DDNS upload task installing accomplished !'