-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ServiceLogonRight.ps1
More file actions
34 lines (29 loc) · 969 Bytes
/
Copy pathGet-ServiceLogonRight.ps1
File metadata and controls
34 lines (29 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Get-ServiceLogonRight.ps1
[CmdletBinding()]
param ()
# Initialize the temporary configuration export filename
$tempConfigFile = "$env:TEMP\tempCfg.ini"
# Export the security policy
$null = $(secedit /export /cfg $tempConfigFile)
# Display the 'SeServiceLogonRight' value.
$currentSeServiceLogonRight = (Get-Content $tempConfigFile |
Select-String "SeServiceLogonRight").ToString().Replace('SeServiceLogonRight = ', '').Split(',')
$currentSeServiceLogonRight | ForEach-Object {
$currentAccount = $_
if ($currentAccount -like "*S-1-5*") {
$sid = ($currentAccount).Replace('*', '')
try {
[System.Security.Principal.SecurityIdentifier]::new("$($sid)").Translate([System.Security.Principal.NTAccount]).Value
}
catch {
$currentAccount
}
}
else {
$currentAccount
}
}
# Clean up
if (Test-Path $tempConfigFile) {
Remove-Item -Path $tempConfigFile -Force -Confirm:$false
}