【发布时间】:2014-12-11 07:55:33
【问题描述】:
我想从 Active Directory 用户和计算机中获取“计算机的唯一 ID”属性。
Computer唯一ID的值为4C4C4544-0039-5310-8031-B9C04F393253
我有以下代码:
$endpoint = "someEndpoint"
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher
$directorySearcher.PageSize = 100
$directorySearcher.SearchScope = [System.DirectoryServices.SearchScope]::Subtree
$directorySearcher.Filter = "(&(objectCategory=computer)(cn=$endpoint)"
$result = $directorySearcher.FindOne()
$result.Properties["objectguid"] # {30 103 159 141 234 5 102 71 128 215 212 4 206 254 198 63}
# Converted to hex = 1E679F8D-EA05-6647-80D7-D404CEFEC63F
$result.Properties["objectsid"] # {1 5 0 0 0 0 0 5 21 0 0 0 160 13 253 83 27 146 29 52 250 235 11 116 142 150 12 0}
# Converted to hex = 1 5 0 0 0 0 0 5 15 0 0 0 A0 D FD 53 1B 92 1D 34 FA EB B 74 8E 96 C 0
$result.Properties["netbootguid"] # {68 69 76 76 57 0 16 83 128 49 185 192 79 57 50 83}
# Converted to hex = 44 45 4C 4C 39 00 10 53 80 31 B9 C0 4F 39 32 53
从所有属性中,只有上述 3 个具有 guid/字节数组的 3 个。
但是,这 3 个值都不匹配我从 Active Directory 用户和计算机 GUI 获得的值。
有人知道我如何从 PowerShell 访问计算机的唯一 ID 属性吗?
【问题讨论】:
-
通过唯一 ID 我假设您的意思是 GUID/UUID?您是否有权访问 AD cmdlet?
Get-ADComputer $endpoint | Select-Object -ExpandProperty ObjectGUID。 this 还建议该值的存储方式与显示的不同,这就是为什么您的最后一个示例很接近 -
$result.Properties["netbootguid"]看起来像您获得的计算机的唯一 ID,前三组中发生了一些奇怪的字节序。 -
@BaconBits 检查我评论中的链接。它涵盖了这一点,我认为链接到更长的解释。前几组中的字节需要反转
标签: powershell active-directory