导出AD用户所属组,查询AD用户(aduser)

$ous="admin","bladmin","af","dd"
for($i=0;$i -lt 2;$i++)
{
$ou= $ous[$i]
$usernames = get-aduser -filter * -SearchBase "ou=$ou,dc=testj,dc=com"
foreach ($username in $usernames)
{
$user = get-aduser $username.name -Properties *
$groups = $user.memberof
$groupall=$null
foreach ($group in $groups)
{
$groupall += $group.split("=")[1].split(",")[0] + ","
}
$user.surname + "," + $user.Description + "," + $groupall |Out-File d:\usercollect.txt -Append
}

}

 

==================

查询单个用户,使用 -filter参数,速度要快很多,如下:

get-aduser -filter 'name -like "*admin*"'

posted on 2013-06-26 20:47  momingliu11  阅读(2293)  评论(0编辑  收藏  举报