Powershell 导出对象SID&;Samaccountname

Powershell 导出对象SID&;Samaccountname,powershell,active-directory,export,Powershell,Active Directory,Export,当前未收到文本文件中ObjectSID的导出,需要调整什么?当前每行仅以“;”开头,然后是samaccountname $ADObjects = Get-ADObject -LDAPFilter "(msexchextensionattribute23=*)" -Properties samaccountname,objectsid -Server myserver1.com Out-File -FilePath C:\temp\AD001CountReport.txt -Append -Inp

当前未收到文本文件中ObjectSID的导出,需要调整什么?当前每行仅以“;”开头,然后是samaccountname

$ADObjects = Get-ADObject -LDAPFilter "(msexchextensionattribute23=*)" -Properties samaccountname,objectsid -Server myserver1.com
Out-File -FilePath C:\temp\AD001CountReport.txt -Append -InputObject ($ADObjects.Count + " Objects with msexchextensionattribute23 set found") 

foreach($ADObject in $ADObjects)
{
    $Export = $ADObject.objectsid + ";" + $ADObject.samaccountname
    $Export | Out-file ("C:\temp\AD001ObjectReport" + ".txt") -Append
    $Export = $null
}

字符串连接失败,因为
objectSid
属性是类型为
System.Security.Principal.SecurityIdentifier
的对象,您无法向其添加/追加字符串。使用对象的
属性获取可以使用的SID字符串:

$Export = $ADObject.objectsid.Value + ";" + $ADObject.samaccountname

听起来objectsid是空的。您是否验证了这是正确的属性名称?
$adobject.SID
(示例:s-1-5-21-288904308-4136710315-2444824263-3544)或
$adobject.ObjectGUID
(示例:e1418d64-096c-4cb0-b903-ebb66562d99d)。@briantist在执行直接拉动时,我得到了与sodawillow类似的结果:
Get-ADUser user1-server myserver1.com-Properties*
但是当从
Get-ADObject
执行类似的拉取操作时,它无法识别domain@sodawillow执行
$adobject.sid
时,也不会给出任何结果