PowerShell AD脚本不能正常工作
问题描述:
由于某些原因,除了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
答
如果没有连接到使用.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
答
你能重试添加FindAll
之前这一行:
$objSearch.PropertiesToLoad.Add("homeDirectory");
Generaly来讲最好是添加到搜索每个要中检索属性。
NOt,这是一定是错误的,但是有没有一个原因你使用完整的.NET类而不是说AD工具或Quest AD工具?使这些事情变得更容易和一个单线 – 2013-05-07 00:12:10
我刚刚发现“广告信息”,这是免费的,但越野车。它可能会诀窍。 – Harmond 2013-05-07 12:56:29