xs0u1x
xs0u1x

Reputation: 25

Having issues passing input from textbox

I'm having an issues reading input from a textbox in PowerShell. Code below:

$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)

So you type the userid in the textbox titled useridbox, click the button and PowerShell is not actually reading the value entered. I keep getting the error message

Set-ADUser : Cannot find an object with identity: ''

I'm not sure if my scope

$script:id = $useridbox.Text; 

is correct or if I have to declare the variable earlier in the script or what exactly I'm missing here that is causing this.

Upvotes: 0

Views: 121

Answers (1)

xs0u1x
xs0u1x

Reputation: 25

Well I feel like an idiot now but I found the problem.

For some reason the code block

$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)

Defining the textbox labelled "useridbox" was in my script two times and I have no idea why. I deleted the extra one and my script worked perfectly.

Thank you everybody that attempted to answer.

Upvotes: 1

Related Questions