mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
26 lines
860 B
PowerShell
26 lines
860 B
PowerShell
function Install-IcingaPowerShellService()
|
|
{
|
|
param(
|
|
$Path,
|
|
$Username,
|
|
[SecureString]$Password
|
|
);
|
|
|
|
if ((Test-Path $Path) -eq $FALSE) {
|
|
throw 'Please specify the path directly to the service binary';
|
|
}
|
|
|
|
$Path = [string]::Format(
|
|
'{0} \"{1}\"',
|
|
$Path,
|
|
(Get-IcingaPowerShellModuleFile)
|
|
);
|
|
|
|
$ServiceCreation = Start-IcingaProcess -Executable 'sc.exe' -Arguments ([string]::Format('create icingapowershell binPath= "{0}" DisplayName= "Icinga PowerShell Service" start= auto', $Path));
|
|
|
|
if ($ServiceCreation.ExitCode -ne 0) {
|
|
throw ([string]::Format('Failed to install Icinga PowerShell Service: {0}{1}', $ServiceCreation.Message, $ServiceCreation.Error));
|
|
}
|
|
|
|
return (Set-IcingaAgentServiceUser -User $Username -Password $Password -Service 'icingapowershell');
|
|
}
|