1
我一直在面對這個問題,它似乎沒有結束,希望你能幫助我。活動目錄查詢返回它不應該的空字段
我在Powershell腳本中針對Active Directory進行LDAP查詢。獲取正確的這點是我的代碼:
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=ivegotusers,DC=global,DC=foo,DC=com")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
#Write-Host $objSearcher
$colProplist = "name", "sn", "whenCreated", "whenChanged", "createTimeStamp", "modifyTimeStamp", "displayName", "mailNickName"
foreach ($i in $colPropList){
$objSearcher.PropertiesToLoad.Add($i)
}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults){
$objItem = $objResult.Properties;
Write-Host -NoNewLine $objItem.name
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.displayName;
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.sn;
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.whenCreated;
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.createTimeStamp;
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.whenChanged;
Write-Host -NoNewLine "|";
Write-Host -NoNewLine $objItem.modifyTimeStamp;
Write-Host "|";
}
所以我們應該得到的輸出爲每個查詢匹配行,作爲行格式如下: 名稱|顯示名| SN | whenCreated | createTimeStamp | whenChanged | modifyTimeStamp 對不對?
我檢查了ADSI Edit中的數據,很多用戶都有這些數據;儘管如此,產量爲
name1||sn1||||
name2||sn2||||
name3||sn3||||
name4||sn4||||
name5||sn5||||
那些相同的用戶,而且也並不比seted這兩個領域較爲單一線。
任何人都可以幫我弄清楚這裏發生了什麼嗎?
注意:由於服務器的設置,我無法使用Powershell上的ActiveDirectory導入。
感謝您的時間! 弗拉德
不能相信它的工作!只有全部小寫的屬性名稱纔有用。當然,我現在想知道如何在自己之前設法不嘗試這個。非常感謝你! – Vladimir 2013-05-06 14:05:16
非常歡迎。 – serialhobbyist 2013-05-07 09:50:09