Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms Powershell输入框_Winforms_Powershell - Fatal编程技术网

Winforms Powershell输入框

Winforms Powershell输入框,winforms,powershell,Winforms,Powershell,我正在尝试使用一个输入框来提示用户输入组,而不是硬编码。提前谢谢 $users = gc "C:\Users\raw.admin\Documents\PowerShell Scripts\users_list.txt" foreach($u in $users) { Add-ADGroupMember XA-MS_Products -Members $u } 我发现了别人的代码,但我不知道如何使它适应我想要的 function point ($x,$y) { New-Objec

我正在尝试使用一个输入框来提示用户输入组,而不是硬编码。提前谢谢

$users = gc "C:\Users\raw.admin\Documents\PowerShell Scripts\users_list.txt"

foreach($u in $users)
{
   Add-ADGroupMember XA-MS_Products -Members $u
} 
我发现了别人的代码,但我不知道如何使它适应我想要的

function point ($x,$y)
{
   New-Object Drawing.Point $x,$y
}

[reflection.assembly]::LoadWithPartialName("System.Drawing") > $null
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") > $null

$form = New-Object Windows.forms.form
$form.text = "Drive Space Results"
$form.size = point 600 400

$label1 = New-Object Windows.forms.Label
$label1.location = point 225 25
$label1.size = point 300 25
$label1.text = "MASTER DOMAIN ONLY"


$label2 = New-Object Windows.forms.Label
$label2.location = point 25 75
$label2.size = point 120 100
$label2.text = "Enter Server Name:"

$input1 = New-Object Windows.forms.TextBox
$input1.location = point 150 75
$input1.size = point 350 75


$run = New-Object Windows.forms.Button
$run.text="RUN"
$run.Location = point 150 120
$run.size = point 100 50
$run.add_click({
   runCall($input1.text)
})

$exit = New-Object Windows.forms.Button
$exit.text="EXIT"
$exit.Location = point 300 120
$exit.size = point 100 50
$exit.add_click({
   $form.close()
})

$out = New-Object Windows.forms.TextBox
$out.location = point 25 200
 $out.size = point 525 150
$out.Anchor = "bottom"
$out.Multiline = $true

$form.controls.addrange(($label1,$label2,$input1,$run,$exit,$out))
$form.add_shown({$form.Activate()})
$form.ShowDialog()


我建议您避免使用自定义表单,它需要大量代码,只需使用默认的
InputBox
。这里有一个快速的例子

Add-Type -AssemblyName Microsoft.VisualBasic;
$value = [Microsoft.VisualBasic.Interaction]::InputBox('Enter group name', 'XA Group', '')

$value
中,您将看到用户输入的文本

,这是一个选项,但我很想知道如何向用户显示一个弹出框。你的答案没有理由不起作用。我是Powershell的新手,希望在我创建的脚本中添加一些东西。这正是我想要的。谢谢。您能告诉我如何使用我发布的示例代码吗?下面是一个示例,它向您展示了如何使用powershell中的winform的基本知识。上面的代码看起来很相似:我想您只需要将
$form.ShowDialog()
更改为
[void]$form.ShowDialog()
,并添加一行新代码,如
$x
,将用户的输入保存到变量中(
$x
Add-Type -AssemblyName Microsoft.VisualBasic;
$value = [Microsoft.VisualBasic.Interaction]::InputBox('Enter group name', 'XA Group', '')