首页 > 解决方案 > 将 AD 用户名插入组合框

问题描述

我想将我所有的 AD 用户名插入到没有“@()”的 powershell 组合框中。

我可以按照我的预期查询 AD - 只列出我想要的用户名。但是当我将它们添加到组合框中时,“@()”将它们包围起来。

function Get-TemplateUser(){

    $adusernames = Get-ADUser -Filter {enabled -eq $true} | ? {$_.GivenName -notlike ""} | select Name

    foreach($user in $adusernames){
        $ComboBoxTemplate.Items.Add($user)
    }
}


我希望它是这样的:

“用户 A” “用户 B”

但我得到的是:

@("用户 A") @("用户 B")

标签: powershellactive-directory

解决方案


有两种方法可以做到这一点。

# This way, good if you only have to extract 1 property, bad if you need multiple.
... | select -ExpandProperty Name

# This is another way, good if your original object has more than 1 property
$ComboBoxTemplate.Items.Add($user.Name)

推荐阅读