在这里编写一个PowerShell脚本,将AD中的一些数据填充到excelsheet中。我正在努力解决一个问题..
我用这一行在变量$ accounts中读出我想要的东西:
$accounts = Get-ADUser -Filter * -SearchBase "OU=technicalaccounts,OU=ztechnical,DC=XXX,DC=XXX,DC=XX" -Properties memberof, passwordlastset, description, enabled
然后在Foreach中填写excelsheet
$Sheet.Cells.Item($row,1).FormulaLocal = $value.name
$Sheet.Cells.Item($row,2).FormulaLocal = $value.description
$Sheet.Cells.Item($row,3).FormulaLocal = $value.passwordlastset
$Sheet.Cells.Item($row,4).FormulaLocal = $value.enabled
$Sheet.Cells.Item($row,5).FormulaLocal = $value.memberof
当它正在执行此操作时会出现问题
$Sheet.Cells.Item($row,5).FormulaLocal = $value.memberof
错误说明了这一点:
Ausnahme beim Festlegen von“FormulaLocal”:“Ausnahme von HRESULT:0x800A03EC” 在\ Get-TechUser.ps1:57 Zeichen:9 + $ Sheet.Cells.Item($ row,5).FormulaLocal = $ value.memberof + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ + CategoryInfo:NotSpecified:(:) [],SetValueInvocationException + FullyQualifiedErrorId:CatchFromBaseAdapterSetValueTI
这是一个数组中的数组吗?
无论如何,谢谢你的建议:)答案 0 :(得分:1)
memberof属性是Group Memberships的集合(ADPropertyValueCollection)。 您可以使用加入运算符:
$Sheet.Cells.Item($row,5).FormulaLocal = $value.memberof -join ";"