Using powershell, how do I grant “Log on as service” to an account?

后端 未结 8 883
感情败类
感情败类 2020-12-15 17:40

I\'m trying to use powershell to configure the account credentials, but I need to grant the account \"Log on as a service\" right in order for it to work. How can I do this

8条回答
  •  悲哀的现实
    2020-12-15 18:20

    This is how I solved it:

    Based on: this article

    You can download Carbon from here

    First import Carbon module as follows:

    Import-Module -Name $Path_To_Carbon -Global -Prefix CA
    
    [array]$UserPrivileges = Get-CAPrivileges -Identity $UserName;
    [bool]$LogOnAsAServiceprivilegeFound = $false;
    
    if ($UserPrivileges.Length > 0)
    {
        if ($UserPrivileges -contains "SeServiceLogonRight")
        {
            $LogOnAsAServiceprivilegeFound = $true;
        }
    }
    
    if ($LogOnAsAServiceprivilegeFound -eq $false)
    {
        Grant-CAPrivilege -Identity $UserName "SeServiceLogonRight"
    }
    

提交回复
热议问题