export users from local policies

Konstantin Nayko 1 Reputation point
2021-07-15T11:30:14.647+00:00

Hi all!
Anyone knows easy way to export users with Powershell from secpol.msc -> local policies -> user rights assignment -> Log on as a service?
i can't find any solution.
Thanks for your help

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,931 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,376 Reputation points Microsoft Vendor
    2021-07-15T14:11:27.97+00:00

    Hi,

    You can use secedit to export the security settings.

    $file = New-TemporaryFile  
    secedit.exe /export /cfg $file  
    $ServiceLogon = Get-Content -Path $file | Where-Object {$_ -match 'SeServiceLogonRight'}  
    $pattern = '(?<=\*).+?(?=,|$)'  
    [regex]::Matches($ServiceLogon,$pattern).value | ForEach-Object {  
        $SID = New-Object System.Security.Principal.SecurityIdentifier($_)   
        try{  
            $ErrorActionPreference = "Stop"  
            $SID.Translate( [System.Security.Principal.NTAccount]).Value  
        }  
        catch [System.Management.Automation.MethodInvocationException]{  
            $SID.Value  
        }  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments