How To Set Log On As Credentials for a Service via Powershell

Andrea Del Giudice 6 Reputation points
2021-10-20T06:12:17.513+00:00

Hi there,

I would like to create a script in PowerShell that facilitates people to change the Log On As information for a specific Service with local admin passwords.

There is an app, for Dell computers, called SupportAssist. This app only works when logged in with a local administrator session but on the Dell community I have found out that with a little trick, you can get it working also when logged in as a normal user (with no admin rights): https://www.dell.com/community/SupportAssist-for-PCs/SupportAssist-run-as-admin/td-p/7187490

  • Run Services as administrator
  • Type the local admin credentials (local - no domain → .\administrator)
  • Find and double-click the service Dell SupportAssist
  • Go to the Log On tab
  • Tick This account under Log on as
  • Type your local admin credentials (local - no domain → .\administrator)
  • Click on Apply
  • Stop and restart the service

141955-dellsupportassist.jpg

So I would like to automate most of the steps leaving the users only the burden of having to type the local admin password. When googling about this, I found this page https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-service?view=powershell-7.1 and I thought that the following lines would be enough:

$credential = Get-Credential  
Set-Service -Name "Dell SupportAssist" -Credential $credential  

The problem is that the Get-Credential cmdlet wants me to type domain credentials but I need to set the Log on as config of the Service as local administrator instead:

142001-get-credential.jpg

Maybe there is another cmdlet to do this or do I have to add some more lines to specify that I am referring to the localhost? Any help would be much appreciated.

Thanks in advance

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2021-10-20T15:07:58.233+00:00

    If you're using PowerShell 7 the Set-Service cmdlet can manage this.

    If, on the other hand, you're using PowerShell 5, you can use WMI to handle it. Have a look at this: powershell-script-to-change-service-account

    0 comments No comments