Repository navigation
Expand file tree
/
Copy pathGet-AllScheduledTasks.ps1
More file actions
68 lines (61 loc) · 2.52 KB
/
Copy pathGet-AllScheduledTasks.ps1
File metadata and controls
68 lines (61 loc) · 2.52 KB
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
<#
.SYNOPSIS
Listet alle geplanten Aufgaben eines Rechners auf, wahlweise als
Gitteransicht, JSON-Datei oder Pipeline-Ausgabe.
.DESCRIPTION
Sammelt Aufgaben samt Ausfuehrungskonto, Trigger und letztem Ergebnis.
Ueber drei Schalter am Dateianfang laesst sich steuern, ob das Ergebnis
in Out-GridView landet, als JSON geschrieben wird oder in die Pipeline
geht.
.NOTES
Fuer einen automatisierten Lauf $OutGridViewOutput auf $false setzen -
sonst blockiert das Fenster.
Ohne administrative Rechte bleiben Aufgaben anderer Benutzer unsichtbar;
das Skript weist darauf hin.
#>
$OutGridViewOutput = $false # Set to $false, if there is something being automated...
$jsonExport = $true
$jsonExportPath = "c:\install\Tasks_" + $env:COMPUTERNAME + ".json"
$pipelineoutput = $true
# Prüfen, ob das Skript mit administrativen Rechten läuft
$adminCheck = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $adminCheck) {
Write-Host "Dieses Skript muss mit administrativen Rechten ausgeführt werden!" -ForegroundColor Red
} else {
$erg = @()
# Falls der Benutzer Admin ist, werden die Scheduled Tasks ausgelesen
Get-ScheduledTask | ForEach-Object {
$taskName = $_.TaskName
$taskPath = $_.TaskPath
$description = $_.Description
$principal = $_.Principal.UserId
$logonType = $_.Principal.LogonType
$runLevel = $_.Principal.RunLevel
$_.Actions | ForEach-Object {
$program = $_.Execute
$arguments = $_.Arguments
$workingdirectory = $_.WorkingDirectory
$erg += [PSCustomObject]@{
User = $principal
LogonType = $logonType
RunLevel = $runLevel
TaskName = $taskName
Program = $program
Arguments = $arguments
WorkingDirectory = $workingdirectory
TaskPath = $taskPath
Description = $description
}
}
}
if ($jsonExport -eq $true) {
$erg | ConvertTo-Json -Depth 20 | Out-File -FilePath $jsonExportPath -Force
Write-Host "File Exported to $jsonExportPath" -ForegroundColor Green
}
if ($OutGridViewOutput -eq $true) {
$erg | Out-GridView -Title "Scheduled Tasks" -OutputMode Multiple
}
if ($pipelineoutput -eq $true) {
$erg
}
}