有人可以请一个简单的-ldapfilter建议

时间:2013-03-29 14:08:43

标签: powershell

大家好,有人可以帮我理解为什么生成的导出文件不包含任何信息。对于导入的.csv文件中的每个ISID(我的设置登录名称的缩写),我想找到相应的samAccountName并导出列出的属性...

Add-PSSnapin Quest.ActiveRoles.ADManagement
connect-qadservice US2.k.com -proxy
$groupName = Import-csv c:\ExportDL\LockedAccounts.csv
write-host "This window will close when done"_ADmembers.csv" will be created" -ForegroundColor Green
ForEach ($ISID in $groupName) {
get-qaduser -ldapfilter "(&(objectCategory=person)(objectClass=user)(samaccountname=$ISID))" 
    -includedproperties samAccountName,accountExpires,edsvaParentCanonicalName,edsaAccountIsDisabled,passwordLastset,department,manager,distinguishedName,displayName | 
    select edsvaParentCanonicalName,displayName,samAccountName,name,edsaAccountIsDisabled,logonName,
    lastName,firstName,manager,accountExpires,passwordLastset | 
        export-csv C:\ExportDL\LockedAccounts_ADmembers.csv
}

我为糟糕的缩进道歉。我无法想象四个空格代码阻塞:(

1 个答案:

答案 0 :(得分:1)

这应该可行,但有趣的是知道LockedAccounts.csv文件的内容:

Add-PSSnapin Quest.ActiveRoles.ADManagement
connect-qadservice US2.k.com -proxy
$groupName = Import-csv c:\ExportDL\LockedAccounts.csv 
write-host "This window will close when done"_ADmembers.csv" will be created" -Fore Green

( $groupName | select -expa ISID | get-qaduser -includedproperties samAccountName,accountExpires,ParentCanonicalName,
AccountIsDisabled,passwordLastset, department,manager,distinguishedName,displayName | 
select ParentCanonicalName,displayName,samAccountName,name,AccountIsDisabled,logonName,
       lastName,firstName,manager,accountExpires,passwordLastset ) |
export-csv C:\ExportDL\LockedAccounts_ADmembers.csv -NoTypeInformation 

如果ISID列包含sAMAccountName,则不需要ldap queryQADs命令会通过pipe或{{-identity接受它作为输入1}}参数