导出ObjectSID& SAM帐户

时间:2016-06-29 19:00:31

标签: 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 -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
}

1 个答案:

答案 0 :(得分:0)

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

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