Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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 从文本框传递输入时出现问题_Winforms_Powershell - Fatal编程技术网

Winforms 从文本框传递输入时出现问题

Winforms 从文本框传递输入时出现问题,winforms,powershell,Winforms,Powershell,从PowerShell中的文本框读取输入时遇到问题。代码如下: $button6 = New-Object System.Windows.Forms.Button $button6.Text = "Disable" $button6.Width = 60 $button6.Height = 30 $button6.Add_Click({ $script:id = $useridbox.Text; $script:db = $disabledby.Text; $script:da

从PowerShell中的文本框读取输入时遇到问题。代码如下:

$button6 = New-Object System.Windows.Forms.Button
$button6.Text = "Disable"
$button6.Width = 60
$button6.Height = 30
$button6.Add_Click({
   $script:id = $useridbox.Text;
   $script:db = $disabledby.Text;
   $script:date = Get-Date;
   Set-ADUser -Identity $id -Description "Disabled on $date by $db";
   Disable-ADAccount -Identity $id;
   Move-ADObject -Identity (Get-ADUser $id).ObjectGuid -TargetPath 'ou=Disabled and Terminated Accounts, dc=domain, dc=domain';
})

$button6.Location = New-Object System.Drawing.Point(136, 251)
$button6.Font = "Microsoft Sans Serif,10"
$Form.Controls.Add($button6)
因此,在名为useridbox的文本框中键入userid,单击该按钮,PowerShell实际上不会读取输入的值。我一直收到错误信息

Set ADUser:找不到标识为的对象:

我不确定我的范围

$script:id = $useridbox.Text; 

是正确的,或者如果我必须在脚本的前面声明变量,或者我在这里遗漏了什么导致了这一点

我现在觉得自己像个白痴,但我发现了问题所在

由于某种原因,代码块

$useridbox = New-Object system.windows.Forms.TextBox
$useridbox.Width = 117
$useridbox.Height = 20
$useridbox.location = new-object system.drawing.point(136,18)
$useridbox.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($useridbox)
在我的脚本中定义了两次名为useridbox的文本框,我不知道为什么。我删除了多余的一个,我的脚本工作得很好


谢谢所有试图回答的人

$useridbox.Text是否提供了您认为它提供的文本?您的代码太不完整,我们无法告诉您。当我声明变量$Script:id=$useridbox.Text;我的想法是,当单击按钮时,它将获取当时输入文本框$useridbox的任何文本。它应该获取单击按钮时文本框中存在的任何文本。