$inf = "$env:TEMP\secpol.inf"
secedit /export /cfg $inf /areas USER_RIGHTS
$content = Get-Content $inf
if ($content -match "SeLockMemoryPrivilege") {
# Если строка есть, добавляем пользователя к ней
$content = $content -replace "SeLockMemoryPrivilege = ", "SeLockMemoryPrivilege = *$((New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([System.Security.Principal.SecurityIdentifier]).Value),"
} else {
# Если строки нет, добавляем её в секцию [Privilege Rights]
$idx = ($content | Select-String "\[Privilege Rights\]").LineNumber
$content = $content[0..$idx] + "SeLockMemoryPrivilege = *$((New-Object System.Security.Principal.NTAccount($env:USERNAME)).Translate([System.Security.Principal.SecurityIdentifier]).Value)" + $content[($idx+1)..($content.Length-1)]
}
$content | Set-Content $inf -Encoding Unicode
secedit /configure /db secedit.sdb /cfg $inf /areas USER_RIGHTS /overwrite /quiet