Change a Service to a Network account after install

Comments

2 comments

  • Colby Bouma

    Here's another option to try:

    $ServiceName = 'Elastic Agent'
    $UserName = 'Fancy Name'

    # Please use a safe way to handle passwords, such as one of the methods from Kris's blogs:
    # https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1/
    # https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-2/
    $Password = 'Fancy Password'

    Stop-Service -Name $ServiceName

    # Change the 'Log on as' credential.
    # Inspired by: https://adamtheautomator.com/powershell-service-logon-account/
    $ServiceObject = Get-WmiObject -Query "SELECT * FROM Win32_Service WHERE Name = '$ServiceName'"
    $null = $ServiceObject.Change($null,$null,$null,$null,$null,$null,$UserName,$Password)

    Start-Service -Name $ServiceName
    1
    Comment actions Permalink
  • Kdave

    You can use a Powershell step after the install is done, you can use powershell step and use set-service and specify the log on account and use restart service

    1
    Comment actions Permalink

Please sign in to leave a comment.