【发布时间】:2017-09-06 10:34:12
【问题描述】:
目前,我正在使用以下命令获取所有 Active Directory 用户:
$users = Get-AdUser -Filter {(Enabled -eq "True")} -Properties Description
在此之后,我以这种方式对列表进行各种操作:
foreach ($user in $users)
{
if($user.Description -eq "Admin")
{
Write-Host "This is an admin!"
#Here comes the code that adds the admin to a new list
}
if($user.Description -eq "Secretary")
{
Write-Host "This is a Secretary!"
#Here comes the code that adds the secretaries to a new list
}
}
然而,我想做的是将foreach 中的用户添加到一个新的用户列表中(这样我就可以按他们的描述对他们进行分组,然后再做一些事情,比如显示他们的姓名、金额……)
我的方法是什么?
【问题讨论】:
标签: list powershell data-manipulation