使用 PowerShell 在 Active Directory Users and Computers 中查找 SID。安全标识符或 SID 是分配给域控制网络上的每个 Windows 用户、组或计算机的唯一 ID 号码。因此,例如,如果我们曾试图管理文件和文件夹权限或浏览注册表,我们可能会看到一个长字符串值,类似于 S-1-5-21-3011698416-3634052959-2884390752-500。如果您以前见过类似的内容,那么您已经遇到过 SID。
每个用户、组或计算机都有一个唯一的 SID。如果我们以前从未听说过 SID,可能会想知道它们的目的是什么,以及它如何在 Active Directory (AD) 中起作用。毕竟,我们通常不会在眼前直接看到这些安全标识符。
本文将解释什么是 SID,如何在活动目录用户和计算机中查找 SID,并共享使用 Windows PowerShell 获取 SID 的多个命令。
在 Active Directory 中查找 SID

SID 报告前提条件
要使用本文中涵盖的一系列 Active Directory 命令及其示例,请确保我们具备以下条件:
- 连接到 AD 域的 Windows PC 上
- 以具有至少读取权限的 AD 用户帐户登录
- 已安装并导入 PowerShell Active Directory 模块
免费尝试我们的 Active Directory SID 报告解决方案
試用我們免費,訪問所有功能。- 提供200多個廣告報告模板。輕鬆定製您自己的廣告SID報告。
安全識別符介紹
A Security Identifier or SID is a unique string of values assigned to each security principal and security group by an authority, such as a Windows domain controller. When a security group or principal is created, security identification is made automatically. Once created, the SID is saved in the security database and can be accessed as needed.
將SID與使用者權利結合,Windows在我們每次登錄系統時都會給予我們訪問令牌。這個訪問令牌提供安全上下文,並給予我們適當的權限和權利來管理我們的Windows系統。因此,SID是Windows安全模型的重要部分之一。
除了自動生成的SID外,Windows還有一些眾所周知的通用SID,例如Everyone、Local Authority、World、NT Authority和All Services。以下表格列出了這些眾所周知的通用SID。
Value | Universal Well-Known SID | Identifies |
---|---|---|
S-1-0-0 | Null SID | A group with no member objects. This SID is often used when a SID value is null or unknown. |
S-1-1-0 | World | A group that includes everyone or all users. |
S-1-2-0 | Local | Users who log on to local (physically connected) |
S-1-2-1 | Console Logon | A group includes users logged on the physical console. |
S-1-3-0 | Creator Owner ID | A SID to be replaced by the user’s security identifier who created a new object. This SID is used in inheritable ACEs. |
S-1-3-1 | Creator Group ID | A SID is replaced by the primary-group SID of the user who created a new object. Use this SID in inheritable ACEs. |
S-1-3-2 | Creator Owner Server | |
S-1-3-3 | Creator Group Server | |
S-1-3-4 | Owner Rights | A SID that represents the current owner of the object. When an ACE that carries this SID is applied to an object, the system ignores the object owner’s implicit READ_CONTROL and WRITE_DAC permissions for the object owner. |
S-1-4 | Non-unique Authority | A Security Identifier that represents an identifier authority. |
S-1-5 | NT Authority | A Security Identifier that represents an identifier authority. |
S-1-5-80-0 | All Services | A group includes all service processes configured on the system. The operating system controls membership. |
如果我們想了解更多關於安全識別符的信息,請點擊此鏈接查看其官方Microsoft文檔。
使用PowerShell在Active Directory對象中查找SID
使用 PowerShell,我們可以在每個層級找到每個對象的不同 SID。SID 位於使用者、群組或電腦對象的屬性中。我們將使用 Select-Object 命令從 PowerShell 對象中提取 SID 屬性。
在接下來的部分中,我們將從獲取當前已登錄用戶的 SID 開始,然後逐步向上遍歷到森林中所有域的頂部。
在 PowerShell 中獲取當前活動目錄用戶 SID
我們可以使用Get-LocalUser cmdlet 在 PowerShell 中獲取當前用戶 SID,該命令獲取用戶帳戶詳細信息。例如,運行以下命令以獲取當前已登錄用戶 SID。
Get-LocalUser -Name $env:USERNAME | Select-Object sid
在上述 PowerShell 腳本中,Get-LocalUser 獲取由環境變量$env:USERNAME指定的用戶帳戶詳細信息。

$env:USERNAME 是一個環境變量,保存有關操作系統環境和程序的信息。此數據包括操作系統路徑、Windows 安裝目錄的位置以及操作系統使用的進程數。PowerShell 可以訪問、管理和更改環境變量。
在 PowerShell 中獲取本地用戶 SID
在服务器上,本地用户帐户被保存。我们可以为这些帐户在单个系统上授予访问权限和权限,但只限于该台机器。本地用户帐户是用于保护和控制服务或用户访问独立或成员服务器资源的安全原则。
Get-LocalUser通过 PowerShell 返回本地用户的 SID,如下所示。使用 Get-LocalUser 命令时,我们尚不需要加载和导入 AD 模块。
Get-LocalUser -Name 'johndoe' | Select-Object sid
PowerShell 脚本指定了要获取本地用户 SID 的本地用户名。
在 PowerShell 中获取活动目录用户 SID
由于我们将运行活动目录命令,因此需要导入已导入的 AD 模块。
Import-Module ActiveDirectory
我们可以使用 Get-ADUser cmdlet 获取活动目录用户 SID,以获取一个或多个 AD 用户帐户的详细信息。运行以下命令。
Get-AdUser -Identity toms | Select Name, SID, UserPrincipalName
在上述 PowerShell 脚本中,Get-ADUser cmdlet 获取了由 Identity 参数指定的 AD 用户 SID。此外,该参数在 PowerShell 中选择了 AD 用户的名称、SID 和用户主体名称属性。
試用我們的Active Directory & Office 365報告與審計工具
試試我們以免費方式。提供數百種報告模板。輕鬆自定義您的AD、Azure AD & Office 365報告。
使用PowerShell獲取Active Directory計算機SID
我們不僅可以從用戶獲取SID,還可以從加入域的計算機獲取。我們可以使用Get-ADComputer命令獲取Active Directory計算機SID。我們可以使用Filter參數從多個AD計算機獲取多個SID。
Get-ADComputer -Filter * | Select-Object Name, SID
在上面的PowerShell中,Get-ADComputercmdlet在Active Directory中獲取計算機帳戶詳細信息,並使用管道運算符選擇Active Directory中計算機的名稱和SID。
使用PowerShell獲取Active Directory組SID
就像使用者和電腦一樣,我們也可以取得一個群組的SID,因為群組被視為AD物件。要取得Active Directory中群組的SID,可以使用Get-ADGroup命令。
Get-ADGroup -Identity SalesLeader | Select-Object Name, SID
Get-ADGroup命令會根據Identity參數在PowerShell腳本中指定的一個群組帳戶。接下來,使用管道運算符選擇Active Directory中群組的名稱和SID屬性。
在PowerShell中取得所有網域的SID
一個Active Directory樹林(AD樹林)是在Active Directory配置中包含網域、使用者、機器和群組規則的邏輯容器。
我們可以使用Active Directory的Get-ADForest命令來找到Active Directory中所有網域的SID,如下所示。
(Get-ADForest).Domains| %{Get-ADDomain -Server $_} | Select-Object name, domainsid
在Active Directory物件中找到SID的結論
我們可以使用 Active Directory cmdlets 如 Get-ADUser, Get-ADComputer, 和 Get-ADGroup 在活動目錄使用者和電腦中尋找 SID。此外,我們還包括了使用 Get-LocalUser 和 Get-ADDomain 分別獲取本地使用者和整個網域的 SID。
Source:
https://infrasos.com/find-sid-in-active-directory-users-and-computers-using-powershell/