powershell - 将 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")
解决方案
有两种方法可以做到这一点。
# 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)
推荐阅读
- docker - 在文件 './docker-compose.yml' 中,卷必须是映射,而不是数组
- javascript - Aerospike,NodeJS。推入对象中的数组
- node.js - 如何中止 node.js 中的 fs.copyFile()
- node.js - 节点 js 与 Oracle DB 的连接给出 DPI-1047
- python - Matplotlib 无法旋转 xticks
- css - 如何对 16:9 图像使用对象拟合?
- javascript - 如何将目录变量的 JavaScript 列表传递给 Python Flask
- javascript - 如何在 Rails 6 中测试网络推送通知?
- reactjs - 如何让我的计时器应用程序在 Expo/React Native 的后台运行
- python - 按字数拆分字符串