# Need a PS script to a add service account to log on as a service

**URL:** <https://forums.powershell.org/t/need-a-ps-script-to-a-add-service-account-to-log-on-as-a-service/13968>\
**Category:** PowerShell Help\
**Created:** [March 16, 2020, 9:56am UTC](https://forums.powershell.org/t/need-a-ps-script-to-a-add-service-account-to-log-on-as-a-service/13968 "2020-03-16T09:56:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nlong12](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nlong12/32/123_2.png) [@nlong12](https://forums.powershell.org/u/nlong12)\
**Post date:** [March 16, 2020, 9:56am UTC](https://forums.powershell.org/t/need-a-ps-script-to-a-add-service-account-to-log-on-as-a-service/13968/1 "2020-03-16T09:56:02Z")

</div>

Good morning!  
Looking for some help need to add to add a service account to log on as a service from a list of servers. No idea how to accomplish this. Any help would be greatly appreciated

Thank you  
Norm

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [March 16, 2020, 1:51pm UTC](https://forums.powershell.org/t/need-a-ps-script-to-a-add-service-account-to-log-on-as-a-service/13968/2 "2020-03-16T13:51:37Z")

</div>

You’re looking to assign the [user ‘right’ called ‘SeServiceLogonRight’](https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/user-rights-assignment)

You can backup the local security policy to file using something like

```
Start-Process secedit -ArgumentList "/export /areas USER_RIGHTS /cfg $FileName" -Wait -PassThru
```

Get the user SID using something like

```
$Sid = ((Get-LocalUser $userName -EA 1).SID).Value
```

Modify the Policy (text) file as needed - granting the user(s) as defined by their SID(s) the desired rights  
and finally update the local security policy using something like

```
Start-Process secedit -ArgumentList "/configure /db $env:windir\security\database\secedit.sdb /cfg $FileName /areas USER_RIGHTS /log $($FileName.Replace('.inf','.log'))" -Wait -PassThru
```

Can you put it all together?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/need-a-ps-script-to-a-add-service-account-to-log-on-as-a-service/13968/3 "2024-05-16T20:30:19Z")

</div>


