-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreationScript.ps1
85 lines (75 loc) · 2.42 KB
/
CreationScript.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
75
76
77
78
79
80
81
82
83
84
85
#SECTION VARIABLES
$FileNames = @(
"Monday.jpg",
"Tuesday.jpg",
"Wednesday.jpg",
"Thursday.jpg",
"Friday.jpg",
"Saturday.jpg",
"Sunday.jpg",
"Monday.bmp",
"Tuesday.bmp",
"Wednesday.bmp",
"Thursday.bmp",
"Friday.bmp",
"Saturday.bmp",
"Sunday.bmp",
"wallpaper.ps1")
$Path = $env:USERPROFILE + "\WeekdayWallpaper\"
$ScriptLocation = $path + $FileNames[7]
$Uri = "https://github.com/BlaxadowFire/JapaneseBackground/blob/master/"
$Arguments = '-window hidden -NonInteractive -NoLogo -File "' + $ScriptLocation + '"'
#SECTION VARIABLES END
#SECTION FUNCTIONS
#Downloads give files from base URI to Path
Function DownloadFiles($fileNames)
{
foreach ($fileName in $fileNames)
{
If (!([System.IO.File]::Exists($Path + $fileName)))
{
DownloadFile -fileName $fileName
}
}
}
#Downloads given file from base URI to Path
Function DownloadFile($fileName)
{
$fileUri = $Uri + $fileName + "?raw=true"
$outPutFile = $Path + $fileName
Invoke-WebRequest -Uri $fileUri -OutFile $outputFile
}
Function DirCheck($fileNames)
{
#Checks if Directory exists
if(!(Test-Path $Path))
{
#Create Directory
New-Item -ItemType directory -Path $Path
}
#Download all files if not existing
DownloadFiles -fileNames $fileNames
}
Function Get-SID()
{
#Get Current user SID
$input = whoami /user /fo list
$regexperssion = "SID:\s+([\s\S_]+)"
return [regex]::Match($input,$regexperssion).captures.groups[1].value
}
Function CreateTask()
{
$sid = Get-SID
#Create Task
$TaskName = 'Change Wallpaper'
$Action = New-ScheduledTaskAction -Execute 'powershell.exe'-Argument $Arguments
$Trigger = New-ScheduledTaskTrigger -AtLogOn
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
$Principal = New-ScheduledTaskPrincipal -LogonType Interactive -UserId $sid -Id 'Author' -RunLevel Highest
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal
Register-ScheduledTask -TaskName $TaskName -InputObject $Task -Force
}
#SECTION FUNCTIONS END
#The executed code
Dircheck -fileNames $FileNames
CreateTask