-
Notifications
You must be signed in to change notification settings - Fork 0
/
Salt-Service-Updater.ps1
26 lines (23 loc) · 1.05 KB
/
Salt-Service-Updater.ps1
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
param (
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][SecureString]$Password,
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][String]$UserName,
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][String]$ServiceName
)
function set-serviceCredentials {
param (
[SecureString]$password,
[String]$userName,
[String]$serviceName
)
process {
$Password = (ConvertTo-SecureString -String $($password) -AsPlainText -Force)
New-LocalUser $($userName) -Password $($password)
Add-LocalGroupMember -Group "Administrators" -Member $($userName)
Set-LocalUser -Name $($userName) -PasswordNeverExpires 1
Stop-Service -Name $($serviceName)
$Svc = Get-WmiObject win32_service -filter "name='$($serviceName)'"
$Svc.Change($Null, $Null, $Null, $Null, $Null, $Null, "$($env:COMPUTERNAME)\$($userName)", $($password))
Start-Service -Name $($serviceName)
}
}
set-serviceCredentials -password $Password -userName $UserName -serviceName $ServiceName