$n = 0
foreach ($i in $NameList.Count) {
[void] $listBox.Items.Add($NameList[$n])
$n = $n + 1
}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[string]$a = Read-Host "Введите Имя/Фамилию кириллицей"
[string]$SearchName = "*$a*"
$NameList = @(Get-ADUser -Filter {Name -like $SearchName} -Properties Name | Select-Object -Property Name)
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Выберите пользователя'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Please select a computer:'
$form.Controls.Add($label)
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 80
$n = 0
foreach ($i in $NameList.Count) {
[void] $listBox.Items.Add($NameList[$n])
$n = $n + 1
}
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
$x = $listBox.SelectedItem
$x
}
foreach ($User in $NameList) {
[void] $listBox.Items.Add($User)
}
$User.Name
$NameList = @(Get-ADUser -Filter {Name -like $SearchName} -Properties Name | Select-Object -Property Name)
$NameList = @(Get-ADUser -Filter {Name -like $SearchName} -Properties Name)
$NameList = @(Get-ADUser -Filter {Name -like $SearchName} -Properties Name | Select-Object -ExpandProperty Name)
@()
тоже необязательно, если вам вот прям не нужен массив. foreach будет работать и так