-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschedJOBersteller.ps1
53 lines (36 loc) · 2.3 KB
/
schedJOBersteller.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
<#
taskersteller.ps1
.DESCRIPTION
Erstellt geplante Jobs fuer Scripts
https://github.com/thelamescriptkiddiemax/powershell
#>
#--- Variablen ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$taskhome = "$Env:USERPROFILE\Documents\git\powershell"
$taskscript = "netsharestarter.ps1"
$scripttarget = "$taskhome\$taskscript"
$schedoptions = (New-ScheduledJobOption -RequireNetwork -ContinueIfGoingOnBattery -StartIfOnBattery)
$schedtrigger = (New-JobTrigger -AtLogOn)
$scriptjobname = $taskscript.Replace(".ps1", "")
#--- Vorbereitung -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$stringhost = $stringhost.replace("{Caption=Microsoft"," ").replace("}", " ")
$string1 = [System.String]::Concat(" Erstelle Job ", $scriptjobname, "`n", "`n")
$string2 = [System.String]::Concat(" Joberstellung: ", $jobtest, " !", "`n", "`n")
$jobtesterfolg = "Erfolgreich"
$jobtestfail = "NICHT erfolgreich"
$jobtest = $jobtestfail
#--- Verarbeitung -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Clear-Host
Write-Host $stringhost -ForegroundColor Magenta
Write-Host " FUEHRE MICH ALS ADMIN AUS!" -ForegroundColor DarkRed
Start-Sleep -Seconds 2
Clear-Host
Write-Host $stringhost -ForegroundColor Magenta
Write-Host $string1
Start-Sleep -Seconds 2
Register-ScheduledJob -Name $scriptjobname -FilePath $scripttarget -ScheduledJobOption $schedoptions -Trigger $schedtrigger # Erstelle geplanten Job
if ( Get-ScheduledTask $scriptjobname -ErrorAction Ignore ) { $jobtest = $jobtesterfolg } # Checke geplanten Job
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Clear-Host
Write-Host $stringhost -ForegroundColor Magenta
Write-Host $string2
Start-Sleep -Seconds 4