简体   繁体   English

Powershell使用Get-Aduser查询结果填充列表框

[英]Powershell Populate Listbox with Get-Aduser query results

I am trying to populate a listbox in a Powershell created GUI based off of user input and am getting this error using this. 我试图根据用户输入在Powershell创建的GUI中填充列表框,并使用此错误提示。

$CopyFromTextBox.Add_TextChanged({
$cmdlets = (Get-ADUser -Filter name -like "$($CopyFromTextBox.Text)" ) | Sort-Object 
$UserListBox.ItemsSource = $cmdlets
})

Get-ADUser : A parameter cannot be found that matches parameter name 'like'. Get-ADUser:找不到与参数名称“ like”匹配的参数。

Below is an example of something like what I am trying to do but it actually works. 以下是类似我正在尝试执行的操作的示例,但它确实有效。

$InputBox.Add_TextChanged({
$cmdlets = @(Get-Command -CommandType Cmdlet -Name ("{0}*" -f $InputBox.Text))
$listbox.itemsSource = $cmdlets
})

The way that I was able to get this to work was by using this syntax 我能够使用此语法的方法是使用此语法

$query = $CopyFromTextBox.Text
$cmdlets = (Get-ADUser -Filter "Name -like '*$query*'") 

Thanks for all of the help =) 感谢所有帮助=)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM