30 lines
995 B
PowerShell
30 lines
995 B
PowerShell
function Set-ServiceAccountManagedState {
|
|
<#
|
|
.SYNOPSIS
|
|
Set the service managed account state value to True
|
|
While we could provide a flag to set it to off, we don't do that, because we use gMSA accounts
|
|
|
|
.PARAMETER ServiceName
|
|
The service name to set the state for
|
|
#>
|
|
[CmdletBinding()]
|
|
param (
|
|
[string]$ServiceName
|
|
)
|
|
|
|
$logLead = (Get-logLeadName)
|
|
|
|
if ($null -eq (Get-Service -Name $ServiceName)) {
|
|
Write-Warning "$logLead : [$ServiceName] does not appear to be a valid service. Can not set the service account managed state"
|
|
return
|
|
}
|
|
|
|
Write-Host "$logLead : Setting process to managedaccount $ServiceName true"
|
|
Invoke-SCExe @("managedaccount",$ServiceName,"True")
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "$logLead : Attempt to call sc.exe and set service account managed state errored out. Please review logs"
|
|
} else {
|
|
Write-Host "$logLead : Successfully set the managed state for [$ServiceName]"
|
|
}
|
|
} |