question

AndreaDelGiudice-6659 avatar image
0 Votes"
AndreaDelGiudice-6659 asked RichMatheisen-8856 answered

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

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://docs.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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.