mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-03 04:09:29 -05:00
34 lines
1.2 KiB
PowerShell
34 lines
1.2 KiB
PowerShell
|
|
function Invoke-IcingaWindowsServiceHandlerTask()
|
||
|
|
{
|
||
|
|
param (
|
||
|
|
[string]$ScriptPath = '',
|
||
|
|
[string]$ServiceName = '',
|
||
|
|
[string]$TmpFile = '',
|
||
|
|
[string]$TaskName = '',
|
||
|
|
[string]$TaskPath = ''
|
||
|
|
);
|
||
|
|
|
||
|
|
if ([string]::IsNullOrEmpty($ScriptPath)) {
|
||
|
|
return $null;
|
||
|
|
}
|
||
|
|
|
||
|
|
$ScriptPath = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath $ScriptPath;
|
||
|
|
|
||
|
|
if ((Test-Path $ScriptPath) -eq $FALSE) {
|
||
|
|
Write-IcingaConsoleError 'Unable to execute Job. The provided script path "{0}" does not exist' -Objects $ScriptPath;
|
||
|
|
return $null;
|
||
|
|
}
|
||
|
|
|
||
|
|
$WinAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ([string]::Format("-WindowStyle Hidden -Command &{{ & '{0}' -ServiceName '{1}' -TmpFilePath '{2}' }}", $ScriptPath, $ServiceName, $TmpFile));
|
||
|
|
Register-ScheduledTask -TaskName $TaskName -Action $WinAction -RunLevel Highest -TaskPath $TaskPath | Out-Null;
|
||
|
|
|
||
|
|
Start-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath;
|
||
|
|
|
||
|
|
Wait-IcingaWindowsScheduledTask;
|
||
|
|
|
||
|
|
[string]$TaskOutput = Read-IcingaFileSecure -File $TmpFile;
|
||
|
|
$TaskData = ConvertFrom-Json $TaskOutput;
|
||
|
|
|
||
|
|
return $TaskData;
|
||
|
|
}
|