2017-06-06 64 views
-2

我想使用powershell或cmd編輯本地安全策略的用戶權限分配安全設置。
使用powershell/cmd設置本地安全策略的用戶權限分配

Eg: policy = "change the system time" 
default_security_settings = "local service,Administrators" 
i want to remove everything except Administrators 

我已經試過ntrights命令,但好像不工作 任何命令可以理解

+0

你究竟做了什麼,它在哪裏失敗?請向我們提供您的代碼,以便我們幫助您解決問題,而不是爲您編寫代碼。 – Nick

+0

我已經嘗試過「cmd ntrights + r SeSystemtimePrivilege -u管理員」@Nick –

+0

其中在cmd中顯示ntright命令不存在 –

回答

1

這裏的東西我只是寫。你可以讓它更具動感

function Replace-SecurityTest([string[]]$Usernames,[string]$SecuritySetting, $SaveFile = "C:\Configuration.cfg"){ 
    function Get-SID($USER){ 
     $objUser = New-Object System.Security.Principal.NTAccount("$USER") 
     $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) 
     $strSID.Value 
    } 
    secedit /export /cfg $SaveFile 
    $reader = [System.IO.File]::OpenText($SaveFile) 
    while($null -ne ($line = $reader.ReadLine())) { 
     if ($Line -like "*$SecuritySetting*"){ 
      $reader.Close() 
      $line2 = $line.Remove($line.IndexOf("=")) 
      $line2 += "= " 
      foreach($user in $Usernames){ 
       $line2 += "*$(Get-SID -USER "$user"), " 
      } 
      $line2 = $line2.Remove($line2.LastIndexOf(", ")) 
      (gc $SaveFile).replace("$Line", "$Line2") | Out-File $SaveFile 
      secedit /configure /db c:\windows\security\local.sdb /cfg $SaveFile /areas SECURITYPOLICY 
      rm -force $SaveFile -confirm:$false 
      break 
     } 
    } 

} 

Replace-SecurityTest -Usernames "Administrators" -SecuritySetting "SeSystemtimePrivilege" -SaveFile "C:\Config22.cfg" 
+0

感謝您的幫助,但我的工作解決了[https://gallery.technet.microsoft.com/scriptcenter/Grant-Revoke-Query-user-26e259b0#content] –