Files
syno-scripts/NDTrack/tests/Test-TaskStart.ps1
T
Madzone 1b3e50cd32 function Get-VeeamConfig {
<#
        .SYNOPSIS
            Lädt zentrale Veeam Konfiguration aus JSON.
    #>

    param(

        [string]$Path = (Join-Path ( Split-Path $PSScriptRoot -Parent )"Config\VeeamConfig.json")

    )

    if(!(Test-Path $Path))
    {

        throw `

            "Konfigurationsdatei nicht gefunden: $Path"

    }

    $Content =

        Get-Content `

            -Path $Path `

            -Raw

    $Configuration =

        $Content |

        ConvertFrom-Json

    return $Configuration

}
2026-10-15 13:11:00 +02:00

43 lines
2.7 KiB
PowerShell

$ErrorActionPreference='Stop'
. (Join-Path (Split-Path $PSScriptRoot -Parent) 'NDTrack-Geprueft.ps1') -LibraryOnly
$script:TaskName='NDTRACK'; $script:WindowsLauncher='Run.cmd'
$script:events=@(); $script:hasFile=$true; $script:running=$false; $script:failCreate=$false; $script:failRun=$false
function Resolve-WindowsFolder { 'D:\ndtrack' }
function Invoke-Command { throw 'WinRM darf nicht aufgerufen werden' }
function Test-Path { param($LiteralPath,$PathType,$ErrorAction)
if($LiteralPath -like '*.ndtrack-running'){return $false}
if($LiteralPath -like '\\*'){return $script:hasFile}
Microsoft.PowerShell.Management\Test-Path -LiteralPath $LiteralPath
}
function Assert-TaskNotRunning { if($script:running){throw 'Task aktiv'} }
function Invoke-NativeChecked { param($Program,$Arguments)
if($Program -ne 'schtasks.exe'){throw 'Falsches Programm'}
$script:events += $Arguments[0]
if($Arguments[0] -eq '/Create'){
$script:xmlPath=$Arguments[[array]::IndexOf($Arguments,'/XML')+1]
[xml]$xml=Get-Content -LiteralPath $script:xmlPath -Raw
if($xml.Task.Actions.Exec.WorkingDirectory -ne 'D:\ndtrack'){throw 'Arbeitsverzeichnis falsch'}
if($xml.Task.Actions.Exec.Command -ne '%SystemRoot%\System32\cmd.exe'){throw 'Programm falsch'}
if($xml.Task.Triggers.ChildNodes.Count){throw 'Unerwuenschter Trigger'}
if($script:failCreate){throw 'Exitcode 1 beim Erstellen'}
} elseif($script:failRun){throw 'Exitcode 1 beim Starten'}
}
$credential=[pscredential]::new('DOMAIN\scan',(ConvertTo-SecureString 'test-only' -AsPlainText -Force))
CreateScheduledTask @('server01') $credential
if(($script:events -join ',') -ne '/Create,/Run'){throw 'Reihenfolge falsch'}
if(Test-Path $script:xmlPath){throw 'Temporaere XML nicht entfernt'}
$script:events=@(); $script:hasFile=$false
CreateScheduledTask @('server01') $credential
if($script:events.Count){throw 'Erstellung trotz fehlender CMD'}
$script:hasFile=$true; $script:running=$true
CreateScheduledTask @('server01') $credential
if($script:events.Count){throw 'Aktiven Task ueberschrieben'}
$script:running=$false; $script:failCreate=$true
CreateScheduledTask @('server01') $credential
if(($script:events -join ',') -ne '/Create'){throw 'Start trotz Erstellungsfehler'}
$script:events=@(); $script:failCreate=$false; $script:failRun=$true
$output=@(CreateScheduledTask @('server01') $credential *>&1)
if(($output | Out-String) -match 'START ANGEFORDERT:'){throw 'Falscher Erfolg nach Startfehler'}
if(Test-Path $script:xmlPath){throw 'Temporaere XML nach Fehler vorhanden'}
Write-Host '5 Task-Szenarien bestanden: Erfolg, fehlende CMD, aktiver Task, Create-Fehler, Run-Fehler; XML und Bereinigung geprueft.'