2013-05-06 202 views
0

由於某些原因,除了home目錄外,其他一切正常工作。因爲這一切都是空白的。AD實際上具有這些字段的值,但是此腳本不顯示任何該屬性。有任何想法嗎?PowerShell AD腳本不能正常工作

$objSearch = New-Object System.DirectoryServices.DirectorySearcher 
    $objSearch.PageSize = 15000 
    $objSearch.Filter = $ObjFilter 
    $objSearch.SearchRoot = "LDAP://$dn" 
    $AllObj = $objSearch.FindAll() 
foreach ($Obj in $AllObj) 
     { $objItemS = $Obj.Properties 
      $Ssamaccountname = $objItemS.samaccountname 
      $SsamaccountnameGN = $objItemS.givenname 
      $SsamaccountnameSN = $objItemS.sn 
      $SsamaccountnameEN = $objItemS.mail 
      $SsamaccountnameLS = $objItemS.homeDirectory 
      "$Ssamaccountname`t$SsamaccountnameGN`t$SsamaccountnameSN`t$SsamaccountnameEN`t$SsamaccountnameLS" | Out-File $UserInfoFile -encoding ASCII -append 
     } # End of foreach 
    } # End of ForEach-Object 
+0

NOt,這是一定是錯誤的,但是有沒有一個原因你使用完整的.NET類而不是說AD工具或Quest AD工具?使這些事情變得更容易和一個單線 – 2013-05-07 00:12:10

+0

我剛剛發現「廣告信息」,這是免費的,但越野車。它可能會訣竅。 – Harmond 2013-05-07 12:56:29

回答

0

如果沒有連接到使用.NET我真的很喜歡Quest Active Directory cmdlets

那麼你的命令是:

get-qadUser <UserName or another unique attribute> | Format-List <Attributes> | Out-File MyTextFile.txt 

,獲取可能的屬性列表,您可以:

get-qaduser UserName -includeAllAttribute | fl * | Out-File C:\AllAttributes.txt 
+0

那也行! – Harmond 2013-05-07 15:09:07

0

你能重試添加FindAll之前這一行:

$objSearch.PropertiesToLoad.Add("homeDirectory"); 

Generaly來講最好是添加到搜索每個要中檢索屬性。

+0

我嘗試了你說的話,並得到了一個空的結果。所以現在其他人並沒有顯示你的變化。然後,我嘗試爲sn,mail,givenname和homeDirectory添加$ objSearch.PropertiesToLoad.Add()行,然後像homeDirectory一樣顯示其他屬性。仍然homeDirectory不顯示。 – Harmond 2013-05-07 12:44:22

+0

只需在底層的LDAP部分中提供信息,就可以安全地提供所需的所有屬性。 – JPBlanc 2013-05-08 05:39:52