mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Add support to specify a service for changing the user for
This commit is contained in:
parent
0200b21ac9
commit
a1fd2cca6e
1 changed files with 5 additions and 4 deletions
|
|
@ -2,7 +2,8 @@ function Set-IcingaAgentServiceUser()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
[string]$User,
|
[string]$User,
|
||||||
[securestring]$Password
|
[securestring]$Password,
|
||||||
|
[string]$Service = 'icinga2'
|
||||||
);
|
);
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($User)) {
|
if ([string]::IsNullOrEmpty($User)) {
|
||||||
|
|
@ -14,14 +15,14 @@ function Set-IcingaAgentServiceUser()
|
||||||
$User = [string]::Format('.\{0}', $User);
|
$User = [string]::Format('.\{0}', $User);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ArgString = 'config icinga2 obj= "{0}" password="{1}"';
|
$ArgString = 'config {0} obj= "{1}" password="{2}"';
|
||||||
if($null -eq $Password) {
|
if($null -eq $Password) {
|
||||||
$ArgString = 'config icinga2 obj= "{0}"{1}';
|
$ArgString = 'config {0} obj= "{1}"{2}';
|
||||||
}
|
}
|
||||||
|
|
||||||
$Output = Start-IcingaProcess `
|
$Output = Start-IcingaProcess `
|
||||||
-Executable 'sc.exe' `
|
-Executable 'sc.exe' `
|
||||||
-Arguments ([string]::Format($ArgString, $User, (ConvertFrom-IcingaSecureString $Password))) `
|
-Arguments ([string]::Format($ArgString, $Service, $User, (ConvertFrom-IcingaSecureString $Password))) `
|
||||||
-FlushNewLines $TRUE;
|
-FlushNewLines $TRUE;
|
||||||
|
|
||||||
if ($Output.ExitCode -eq 0) {
|
if ($Output.ExitCode -eq 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue