如何在 Windows 中取得具有特定使用者權限的所有使用者的概覽?

如何在 Windows 中取得具有特定使用者權限的所有使用者的概覽?

我需要檢查是否只有管理員群組(sid:S-1-5-32-544)有權取得檔案或資料夾的所有權(SeTakeOwnershipPrivilege)。

如何獲得擁有此權限的所有使用者/群組的概覽?

我已經找到並嘗試過以下命令:

secedit /export /areas USER_RIGHTS /cfg output.txt

文件中的輸出看起來非常有用:

[Unicode]
Unicode=yes
[權限]
SeNetworkLogonRight = *S-1-5-32-544
...
SeTakeOwnershipPrivilege = *S-1-5-32-544
...
[版本]
簽名 =「$CHICAGO$」
修訂版=1

使用上述方法,我必須將檔案讀入我的 Powershell 腳本,搜尋權限並隨後刪除該檔案。

在沒有外部模組或可執行檔的情況下,是否有其他方法可以在 Powershell 中執行此操作?

感謝您的供應。

乾杯

大衛

答案1

還有另一種方法使用LsaEnumerateAccountsWithUserRightWin32 API 函數。這必須用 C# 編碼(呼叫)在你的腳本中,程式碼定義會非常長而且混亂。

我會避免上述情況並包裝可執行檔。為什麼要重新發明輪子?

# Check this priviledge.
$privilege = 'SeDenyInteractiveLogonRight'

# Create temp file for executable output.
$tempFile = [System.IO.Path]::GetTempFileName()

# Run the executable and wait for it to finish.
Start-Process -FilePath secedit.exe -ArgumentList "/export /areas USER_RIGHTS /cfg $tempFile" -Wait -WindowStyle Hidden

# Run through lines in the output file. 
Get-Content $tempFile -Encoding Unicode | Where-Object { 

    # Where the privilege is listed.
    $_ -match $privilege } | ForEach-Object { 

        # Seperate the key and values.    
        $_.split('=')[1].split(',') | ForEach-Object {

            # Ouput the user/SID values        
            $_.trim()
        }
}

答案2

雖然不是純粹的 PS 解決方案,但仍然是一種選擇。 :)

您可以使用 Microsoft 的 AccessChk 公用程式(在這裡下載) 而不是 SecEdit。

與 SecEdit 不同,AccessChk 輸出到 stdout,因此您可以輕鬆地將其輸出捕獲到 PS 變數中,然後檢查該變數(無需中間檔案)。

就像是:

$privToCheckFor = "SeTakeOwnershipPrivilege"
$groupPrivs = .\accesschk -a administrators *
if ((Out-String -InputObject $groupPrivs).IndexOf($privToCheckFor) -ge 0) {
    Write-Host "Has Privilege"
} else {
    Write-Host "Doesn't Have Privilege"
}

答案3

無恥促銷:查看碳模組(我是創建者/維護者)。它有一個獲取特權將傳回所有主體特權的函數。

答案4

這是解決方案:

(Get-WmiObject -Namespace root\rsop\computer -Class RSOP_UserPrivilegeRight | Where-Object {$_.UserRight -eq "SeTakeOwnershipPrivilege"}).AccountList

相關內容