Solved

Script help with PrimalFormCE: terminate user powershell

Posted on 2014-03-18
10
547 Views
Last Modified: 2014-03-20
I have a working script we use to terminate employees, I'm attempting to craft a gui to go along with it.  I've created a .pff, and am in the process of modifying the ps1 side of things that I found online.  This one was from a pff that contained a textbox, a search button and a DataGridviewRow box.

so I have changed the operators around to match my use but I'm getting a weird error that I am unable to diagnose further, here's the script so far:

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 3/18/2014 3:01 PM
# Generated By: bhart
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button2 = New-Object System.Windows.Forms.Button
$dataGridView1 = New-Object System.Windows.Forms.DataGridView
$button1 = New-Object System.Windows.Forms.Button
$label1 = New-Object System.Windows.Forms.Label
$textBox1 = New-Object System.Windows.Forms.TextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
set-executionpolicy unrestricted -force
Import-Module -Name ActiveDirectory

#Provide Custom Code for events specified in PrimalForms.
	$button1_OnClick={
	$textbox2.Text = ""
	$statusbar1.Text = "Status: Searching..."
	try {
				$users = New-Object System.Collections.ArrayList
				if(!($textbox1.Text)) {
					$userinfo = Get-aduser -ErrorAction Stop | select Name,SAMAccountName
				}
				else {
					$userinfo = Get-aduser $textbox1.Text -ErrorAction Stop | select Name,SAMAccountName
				}
				if($userinfo.count) {
					$userinfo.AddRange($userinfo)
				}
				else {
					$users.Add($userinfo)
				}
				
				$datagridview1.DataSource = $users
				$form1.refresh()
				$statusbar1.Text = ""
				}
			catch {
				[System.Windows.Forms.MessageBox]::Show(
					$_.Exception.Message,
					"Error",
					[System.Windows.Forms.MessageBoxButtons]::OK,
					[System.Windows.Forms.MessageBoxIcon]::Error
					)
				$statusbar1.Text = ""
			}
	
	}
	
	
#TODO: Place custom script here

}

$button2_OnClick= 
{

#Hide from GAL and set Description

Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Description "TERM $(Get-Date)"
Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Replace @{msExchHideFromAddressLists="TRUE"}

#Disable the account

Disable-ADAccount -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop

#Clear Manager field
Set-aduser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -manager $null

#Move the account

Get-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop | Move-ADObject -TargetPath "ou=disabled accounts,dc=difc,dc=root01,dc=org"

Set-ADAccountPassword -identity -Identity $dataGridView1.SelectedCells[0].Value.ToString() -Picture -FileData ([Byte[]]$(Get-Content -Path $textbox2.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -newpassword (ConvertTo-secureString "P@$$word1" -force) -Reset 	

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 259
$System_Drawing_Size.Width = 428
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Primal Form"


$button2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 174
$button2.Location = $System_Drawing_Point
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 54
$System_Drawing_Size.Width = 196
$button2.Size = $System_Drawing_Size
$button2.TabIndex = 4
$button2.Text = "TERMINATE"
$button2.UseVisualStyleBackColor = $True
$button2.add_Click($button2_OnClick)

$form1.Controls.Add($button2)

$dataGridView1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 74
$dataGridView1.Location = $System_Drawing_Point
$dataGridView1.Name = "dataGridView1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 75
$System_Drawing_Size.Width = 368
$dataGridView1.Size = $System_Drawing_Size
$dataGridView1.TabIndex = 3

$form1.Controls.Add($dataGridView1)


$button1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 302
$System_Drawing_Point.Y = 36
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 2
$button1.Text = "Search"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($button1_OnClick)

$form1.Controls.Add($button1)

$label1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 13
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 1
$label1.Text = "Enter Username"

$form1.Controls.Add($label1)

$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 36
$textBox1.Location = $System_Drawing_Point
$textBox1.Name = "textBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 240
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 0

$form1.Controls.Add($textBox1)

#endregion Generated Form Code
{
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Open in new window

0
Comment
Question by:Ben Hart
  • 6
  • 4
10 Comments
 
LVL 10

Expert Comment

by:JoeKlimis
ID: 39938474
Hi
remove line 191 , and the form will load.
also the following have no definition in the form

$textbox2
$statusbar1

I hope this helps

Joe
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39939334
I removed the bracket at line 191 and at line 199, renamed textbox2 to textbox1 (no clue how I missed that), and added a statusbar1.  Saved the pff, exported the PS script and applied teh changes to my existing ps1.  It does run now, however my Search button does nothing.  I've never tried applying the get-aduser results to a datagrid... I've got a feeling that part of the code is incorrect.
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39939367
Updated code:

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 3/19/2014 7:52 AM
# Generated By: bhart
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$statusBar1 = New-Object System.Windows.Forms.StatusBar
$button2 = New-Object System.Windows.Forms.Button
$dataGridView1 = New-Object System.Windows.Forms.DataGridView
$button1 = New-Object System.Windows.Forms.Button
$label1 = New-Object System.Windows.Forms.Label
$textBox1 = New-Object System.Windows.Forms.TextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
{
$button1_OnClick={
	$textbox1.Text = ""
	$statusbar1.Text = "Status: Searching..."
	try {
				$users = New-Object System.Collections.ArrayList
				if(!($textbox1.Text)) {
					$userinfo = Get-aduser -ErrorAction Stop | select Name,SAMAccountName
				}
				else {
					$userinfo = Get-aduser $textbox1.Text -ErrorAction Stop | select Name,SAMAccountName
				}
				if($userinfo.count) {
					$users.AddRange($userinfo)
				}
				else {
					$users.Add($userinfo)
				}
				
				$datagridview1.DataSource = $users
				$form1.refresh()
				$statusbar1.Text = ""
				}
			catch {
				[System.Windows.Forms.MessageBox]::Show(
					$_.Exception.Message,
					"Error",
					[System.Windows.Forms.MessageBoxButtons]::OK,
					[System.Windows.Forms.MessageBoxIcon]::Error
					)
				$statusbar1.Text = ""
			}
	
	}
}

$button2_OnClick= 
{
#Hide from GAL and set Description
"Account is hidden"
Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Description "TERM $(Get-Date)"
Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Replace @{msExchHideFromAddressLists="TRUE"}

#Disable the account
"Account is disabled"
Disable-ADAccount -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop

#Clear Manager field
Set-aduser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -manager $null

#Move the account
"Account is moved to the appropriate OU"
Get-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop | Move-ADObject -TargetPath "ou=disabled accounts,dc=difc,dc=root01,dc=org"
"Account is disabled and moved"
Set-ADAccountPassword -identity -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -newpassword (ConvertTo-secureString "P@$$word1" -force) -Reset 	

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
	$form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 259
$System_Drawing_Size.Width = 428
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Terminate User"

$statusBar1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 237
$statusBar1.Location = $System_Drawing_Point
$statusBar1.Name = "statusBar1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 22
$System_Drawing_Size.Width = 428	
$statusBar1.Size = $System_Drawing_Size
$statusBar1.TabIndex = 5
$statusBar1.Text = ""

$form1.Controls.Add($statusBar1)


$button2.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 174
$button2.Location = $System_Drawing_Point
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 54
$System_Drawing_Size.Width = 196
$button2.Size = $System_Drawing_Size
$button2.TabIndex = 4
$button2.Text = "TERMINATE"
$button2.UseVisualStyleBackColor = $True
$button2.add_Click($button2_OnClick)

$form1.Controls.Add($button2)

$dataGridView1.AllowUserToAddRows = $False
$dataGridView1.AllowUserToResizeRows = $False
$dataGridView1.Anchor = 15
$dataGridView1.AutoSizeColumnsMode = 16
$dataGridView1.BackgroundColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGridView1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 74
$dataGridView1.Location = $System_Drawing_Point
$dataGridView1.MultiSelect = $False
$dataGridView1.Name = "dataGridView1"
$dataGridView1.ReadOnly = $True
$dataGridView1.RowHeadersVisible = $False
$dataGridView1.SelectionMode = 1
$dataGridView1.ShowEditingIcon = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 75
$System_Drawing_Size.Width = 368
$dataGridView1.Size = $System_Drawing_Size
$dataGridView1.TabIndex = 3


$form1.Controls.Add($dataGridView1)


$button1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 302
$System_Drawing_Point.Y = 36
$button1.Location = $System_Drawing_Point
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 2
$button1.Text = "Search"
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($button1_OnClick)

$form1.Controls.Add($button1)

$label1.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 13
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 1
$label1.Text = "Enter Username"

$form1.Controls.Add($label1)

$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 33
$System_Drawing_Point.Y = 36
$textBox1.Location = $System_Drawing_Point
$textBox1.Name = "textBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 240
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 0

$form1.Controls.Add($textBox1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Open in new window

0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 10

Expert Comment

by:JoeKlimis
ID: 39939760
Hi

Also remove lines 29, and 63  the  {    and  }  , this will fill the grid,

I am not able to test as I don't have access to a active directory server to test

Also this article shows a working example of forms and grid views
scripting-guy-march-22-2010.aspx
Joe
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39939928
Thanks Joe.. in order to get all teh extras I can we bought the full powershell studio.  So right now here's what I've got:

#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: 50c5f78e-c925-4728-8f82-e408e068bec4
# Source File: F:\Documents\SAPIEN\Forms\term-user2014-2.pff
#------------------------------------------------------------------------
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
GBQAAB+LCAAAAAAABADNWFlP40gQfl9p/4Pl55DLOUBKLIUAs2hhJkqyzOOoY1dIL+3uqN0mZH79
VvtI7NiB9mhZrZAQLtfR/uqrgx7NwROvIPc3RBH3998sa/RN0mfKCbujDL6SAFwFMriIQpDddqd3
0W1u1+tRq6QV2+qnJ5AhFdztNLujVl6QeF/9DZ6y1H4LY3smaYAuhAya+lfDmokdyMUGGLMWKvKp
aFip9dhposNBs92wphFTkYQxh0hJwtAqWjHq/Qn7pXgBPuYRY7bF8VBje41uO7blbSjzJb6zp4Ir
KVhox8fBA82k2IJU+9RgyihwtaA/wXZ73cuG1e1fjVqZ0hkjDYDtxrE+1F3Cm7LdJWKK8Cmw/kJg
y0YFmBb7UEHQ/E65L3ZhDFXYXCiiovCayIZV9f4IXK/Z1j8f47YaDknf6w86V04P2pdXGYZhFuld
IMtf+iA8ovAEtovBu86w9JXngDwGNDDJp6proL8kq3vuw5vt9suwtxLcK7OQI+t1pJTgn0DXVey4
Ww/na+K9PEsRcf8+IM9gW62zqh8qHHPmOA2rM+wZJy09unHGOleDhtU38X/MmJF2Ul+388f7r5Pl
rYEFVuATDSPCFmrPQKM5FUxIdCIjqLK/fcUWcewX3svh63/Ej6NWrGFCqsrS1r34i6T+E4Xdp1e3
nwtWs8AnjImd7l9LMfH9OZ7Odu8ICytBO287hxAZUdOce5s4RWLbsK4Fgo/T4wHWqmHN6fNGmbiI
lNBUxGRHAQ8fhY+sxHnFDGyPJZdSZeIp+gpTstXFoylo4KRYa0al9ohJpgtgSCBzrJL6LOTZwGoO
xP/G2f58GZwaiN0faIO8xGqiKwbmJ0y+CKFIk4AdEb0lUhPzjdjd+lRR/nzvaTyN48adyBng7BiW
p8F7ncj5v86OmiVcY3bcMaLiDmm7M7GNtgZ41Rk37W7DcgY1x435gjDs6x2kVo6Ntol42iyASG/z
n46aTu1Rk+PgA1kB+wQKMu23JgPrriQmOUwokpzGfCFpt2tTxMR7QpFbjv9Gxcu+ltbrHpVLgnZ7
Ld4+fT9QSZxf3v110mrUdRbOOG3dnk5bu1baytoF/IsPkzCEAKGCMNNNJXs3hf6RcORwgHXY1EtF
EH95vpYMU+B0Vmvnsj8gvjPogYMT6RDpNHIQekIyuvoXEv1OlE+i1scRbyTZ4TT/lVhtZ91fD9ed
jt9vE4ecxDo8ZukczbAJY/ZkdpQvwAEd51iUKBwuORK6VEpToV5CyqpFKXKGriFUUwkxXXQrKckO
2tMoRF5l73O+z72Y4bDW9xHuha6k7OHweh7xxXKi6yD962h4mAnZtY0egyVhVjVFtEYL8CJJseKy
dj4qGpSuiOKslq+JsvL1I0+VlE/kp/qniaqS3kDoSbotgtyqlE5FsCV8n8f8VDIV273U/3UUlEqy
ez0COGEnB6wWV96vpZ3q7Cs8WXDcBtKzBvn9oHAX18pxH5mQvwn8B8iuEPgYFAAA#>
#endregion
#========================================================================
# Code Generated By: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.26
# Generated On: 3/19/2014 12:01 PM
# Generated By: bhart
#========================================================================
#----------------------------------------------
#region Application Functions
#----------------------------------------------

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-term-user2014-2_pff {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object 'System.Windows.Forms.Form'
	$statusBar1 = New-Object 'System.Windows.Forms.StatusBar'
	$button2 = New-Object 'System.Windows.Forms.Button'
	$dataGridView1 = New-Object 'System.Windows.Forms.DataGridView'
	$button1 = New-Object 'System.Windows.Forms.Button'
	$label1 = New-Object 'System.Windows.Forms.Label'
	$textBox1 = New-Object 'System.Windows.Forms.TextBox'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$button1_Click={
		#TODO: Place custom script here
		if(!($textbox1.Text)) {
						$userinfo = Get-aduser -ErrorAction Stop | select name,SAMAccountName
					}
					else {
						$userinfo = Get-aduser $textbox1.Text -ErrorAction Stop | select Name,SAMAccountName
					}
					if($userinfo.count) {
						$users.addrange($userinfo)
					}
					else {
						$users.Add($userinfo)
					}
					
					$datagridview1.DataSource = $users
					$form1.refresh()
					$statusbar1.Text = ""
					}
				
	
	$button2_Click={
		#TODO: Place custom script here
		#Hide from GAL and set Description
	"Account is hidden"
	Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Description "TERM $(Get-Date)"
	Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -Replace @{msExchHideFromAddressLists="TRUE"}
	
	#Disable the account
	"Account is disabled"
	Disable-ADAccount -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop
	
	#Clear Manager field
	Set-aduser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -manager $null
	
	#Move the account
	"Account is moved to the appropriate OU"
	Get-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop | Move-ADObject -TargetPath "ou=disabled accounts,dc=difc,dc=root01,dc=org"
	"Account is disabled and moved"
	Set-ADAccountPassword -identity -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  -ErrorAction Stop -newpassword (ConvertTo-secureString "P@$$word1" -force) -Reset 	
	
	}
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$button2.remove_Click($button2_Click)
			$button1.remove_Click($button1_Click)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form1
	#
	$form1.Controls.Add($statusBar1)
	$form1.Controls.Add($button2)
	$form1.Controls.Add($dataGridView1)
	$form1.Controls.Add($button1)
	$form1.Controls.Add($label1)
	$form1.Controls.Add($textBox1)
	$form1.ClientSize = '428, 259'
	$form1.Name = "form1"
	$form1.Text = "Terminate User"
	#
	# statusBar1
	#
	$statusBar1.Location = '0, 237'
	$statusBar1.Name = "statusBar1"
	$statusBar1.Size = '428, 22'
	$statusBar1.TabIndex = 5
	#
	# button2
	#
	$button2.Location = '33, 174'
	$button2.Name = "button2"
	$button2.Size = '196, 54'
	$button2.TabIndex = 4
	$button2.Text = "TERMINATE"
	$button2.UseVisualStyleBackColor = $True
	$button2.add_Click($button2_Click)
	#
	# dataGridView1
	#
	$dataGridView1.AllowUserToAddRows = $False
	$dataGridView1.AllowUserToResizeRows = $False
	$dataGridView1.Anchor = 'Top, Bottom, Left, Right'
	$dataGridView1.AutoSizeColumnsMode = 'Fill'
	$dataGridView1.BackgroundColor = 'ActiveCaptionText'
	$dataGridView1.Location = '33, 74'
	$dataGridView1.MultiSelect = $False
	$dataGridView1.Name = "dataGridView1"
	$dataGridView1.ReadOnly = $True
	$dataGridView1.RowHeadersVisible = $False
	$dataGridView1.SelectionMode = 'FullRowSelect'
	$dataGridView1.ShowEditingIcon = $False
	$dataGridView1.Size = '368, 75'
	$dataGridView1.TabIndex = 3
	#
	# button1
	#
	$button1.FlatStyle = 'Popup'
	$button1.Location = '302, 36'
	$button1.Name = "button1"
	$button1.Size = '75, 23'
	$button1.TabIndex = 2
	$button1.Text = "Search"
	$button1.UseVisualStyleBackColor = $True
	$button1.add_Click($button1_Click)
	#
	# label1
	#
	$label1.Location = '33, 13'
	$label1.Name = "label1"
	$label1.Size = '100, 23'
	$label1.TabIndex = 1
	$label1.Text = "Enter Username"
	#
	# textBox1
	#
	$textBox1.Location = '33, 36'
	$textBox1.Name = "textBox1"
	$textBox1.Size = '240, 20'
	$textBox1.TabIndex = 0
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$form1.add_FormClosed($Form_Cleanup_FormClosed)
	#Show the Form
	return $form1.ShowDialog()

} #End Function

#Call the form
Call-term-user2014-2_pff | Out-Null

Open in new window



Running the file I get the following error after entering text and clicking button1:

PS F:\Documents\SAPIEN\Forms> ."F:\Documents\SAPIEN\Forms\term-user2014-2.Temp.ps1"
You cannot call a method on a null-valued expression.                              
At F:\Documents\SAPIEN\Forms\term-user2014-2.Temp.ps1:83 char:7                    
+                         $users.Add($userinfo)                                    
+                         ~~~~~~~~~~~~~~~~~~~~~                                    
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException            
    + FullyQualifiedErrorId : InvokeMethodOnNull
0
 
LVL 10

Expert Comment

by:JoeKlimis
ID: 39939959
add  at line 73

This was in the previous script ,   :-)  its undefined so throws an error

	$users = New-Object System.Collections.ArrayList

Open in new window


Regards

Joe
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39940232
:ShakesHead:

Ok my copy/paste skills are lacking, in moving the button1 and button2 parts of the script over I neglected that line for some reason :)

lol thanks joe.

Ok so now the script runs, I can enter an exact SAMAccountName and it will return results.   But my button2 returns an error now

>> Running (term-user2014-2.pff) Script...
>> Platform: V4 64Bit (STA)
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (29): ERROR: At Line: 29 char: 92
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: Set-ADUser : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (29): ERROR: At Line: 29 char: 71
ERROR: +     Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ...
ERROR: +                                                                           ~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
ERROR:
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (30): ERROR: At Line: 30 char: 92
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: Set-ADUser : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (30): ERROR: At Line: 30 char: 71
ERROR: +     Set-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ...
ERROR: +                                                                           ~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
ERROR:
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (34): ERROR: At Line: 34 char: 99
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: Disable-ADAccount : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (34): ERROR: At Line: 34 char: 78
ERROR: +     Disable-ADAccount -Identity $dataGridView1.SelectedCells[0].Value.ToString() -F ...
ERROR: +                                                                                  ~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Disable-ADAccount], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.DisableADAccount
ERROR:
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (37): ERROR: At Line: 37 char: 92
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: Set-ADUser : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (37): ERROR: At Line: 37 char: 71
ERROR: +     Set-aduser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ...
ERROR: +                                                                           ~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
ERROR:
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (41): ERROR: At Line: 41 char: 92
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: Get-ADUser : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (41): ERROR: At Line: 41 char: 71
ERROR: +     Get-ADUser -Identity $dataGridView1.SelectedCells[0].Value.ToString() -FileData ...
ERROR: +                                                                           ~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser
ERROR:
ERROR: Get-Content : Cannot find path 'F:\Documents\SAPIEN\Forms\bentest' because it does not exist.
term-user2014-2.pff (43): ERROR: At Line: 43 char: 104
ERROR: + ... ata ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding Byte -ReadCount 0))  - ...
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : ObjectNotFound: (F:\Documents\SAPIEN\Forms\bentest:String) [Get-Content], ItemNotFoundException
ERROR:     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
ERROR:
ERROR: ConvertTo-secureString : The parameter value "P@word1" is not a valid encrypted string.
term-user2014-2.pff (43): ERROR: At Line: 43 char: 200
ERROR: + ...  -newpassword (ConvertTo-secureString "P@$$word1" -force) -Reset
ERROR: +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [ConvertTo-SecureString], PSArgumentException
ERROR:     + FullyQualifiedErrorId : ImportSecureString_InvalidArgument,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
ERROR:
ERROR: Set-ADAccountPassword : A parameter cannot be found that matches parameter name 'FileData'.
term-user2014-2.pff (43): ERROR: At Line: 43 char: 83
ERROR: + ... lue.ToString() -FileData ([Byte[]]$(Get-Content -Path $textbox1.Text -Encoding B ...
ERROR: +                    ~~~~~~~~~
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Set-ADAccountPassword], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPassword
ERROR:

>> Execution time: 00:00:07
>> Script Ended


So I am not specifying the datagridview selection correctly as an -Identity variable..

I just read about listboxes.. would this be a better way to go, would it make pulling the selection any easier/better?
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39940349
for what it's worth.. the commands I put for the two buttons came from a fully working ps1 script.  I'm just trying to add a gui overlay.
0
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 39941854
Hi

I have updated the script ,  but i dont have exchange installed  so the following 1 lines throws an error for me , but i think the rest is working
	Set-ADUser -Identity $id  -ErrorAction Stop -Replace @{msExchHideFromAddressLists = "TRUE"}

Open in new window



#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: 50c5f78e-c925-4728-8f82-e408e068bec4
# Source File: F:\Documents\SAPIEN\Forms\term-user2014-2.pff
#------------------------------------------------------------------------
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
GBQAAB+LCAAAAAAABADNWFlP40gQfl9p/4Pl55DLOUBKLIUAs2hhJkqyzOOoY1dIL+3uqN0mZH79
VvtI7NiB9mhZrZAQLtfR/uqrgx7NwROvIPc3RBH3998sa/RN0mfKCbujDL6SAFwFMriIQpDddqd3
0W1u1+tRq6QV2+qnJ5AhFdztNLujVl6QeF/9DZ6y1H4LY3smaYAuhAya+lfDmokdyMUGGLMWKvKp
aFip9dhposNBs92wphFTkYQxh0hJwtAqWjHq/Qn7pXgBPuYRY7bF8VBje41uO7blbSjzJb6zp4Ir
KVhox8fBA82k2IJU+9RgyihwtaA/wXZ73cuG1e1fjVqZ0hkjDYDtxrE+1F3Cm7LdJWKK8Cmw/kJg
y0YFmBb7UEHQ/E65L3ZhDFXYXCiiovCayIZV9f4IXK/Z1j8f47YaDknf6w86V04P2pdXGYZhFuld
IMtf+iA8ovAEtovBu86w9JXngDwGNDDJp6proL8kq3vuw5vt9suwtxLcK7OQI+t1pJTgn0DXVey4
Ww/na+K9PEsRcf8+IM9gW62zqh8qHHPmOA2rM+wZJy09unHGOleDhtU38X/MmJF2Ul+388f7r5Pl
rYEFVuATDSPCFmrPQKM5FUxIdCIjqLK/fcUWcewX3svh63/Ej6NWrGFCqsrS1r34i6T+E4Xdp1e3
nwtWs8AnjImd7l9LMfH9OZ7Odu8ICytBO287hxAZUdOce5s4RWLbsK4Fgo/T4wHWqmHN6fNGmbiI
lNBUxGRHAQ8fhY+sxHnFDGyPJZdSZeIp+gpTstXFoylo4KRYa0al9ohJpgtgSCBzrJL6LOTZwGoO
xP/G2f58GZwaiN0faIO8xGqiKwbmJ0y+CKFIk4AdEb0lUhPzjdjd+lRR/nzvaTyN48adyBng7BiW
p8F7ncj5v86OmiVcY3bcMaLiDmm7M7GNtgZ41Rk37W7DcgY1x435gjDs6x2kVo6Ntol42iyASG/z
n46aTu1Rk+PgA1kB+wQKMu23JgPrriQmOUwokpzGfCFpt2tTxMR7QpFbjv9Gxcu+ltbrHpVLgnZ7
Ld4+fT9QSZxf3v110mrUdRbOOG3dnk5bu1baytoF/IsPkzCEAKGCMNNNJXs3hf6RcORwgHXY1EtF
EH95vpYMU+B0Vmvnsj8gvjPogYMT6RDpNHIQekIyuvoXEv1OlE+i1scRbyTZ4TT/lVhtZ91fD9ed
jt9vE4ecxDo8ZukczbAJY/ZkdpQvwAEd51iUKBwuORK6VEpToV5CyqpFKXKGriFUUwkxXXQrKckO
2tMoRF5l73O+z72Y4bDW9xHuha6k7OHweh7xxXKi6yD962h4mAnZtY0egyVhVjVFtEYL8CJJseKy
dj4qGpSuiOKslq+JsvL1I0+VlE/kp/qniaqS3kDoSbotgtyqlE5FsCV8n8f8VDIV273U/3UUlEqy
ez0COGEnB6wWV96vpZ3q7Cs8WXDcBtKzBvn9oHAX18pxH5mQvwn8B8iuEPgYFAAA#>
#endregion
#========================================================================
# Code Generated By: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.26
# Generated On: 3/19/2014 12:01 PM
# Generated By: bhart
#========================================================================
#----------------------------------------------
#region Application Functions
#----------------------------------------------

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-term-user2014-2_pff {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object 'System.Windows.Forms.Form'
	$statusBar1 = New-Object 'System.Windows.Forms.StatusBar'
	$button2 = New-Object 'System.Windows.Forms.Button'
	$dataGridView1 = New-Object 'System.Windows.Forms.DataGridView'
	$button1 = New-Object 'System.Windows.Forms.Button'
	$label1 = New-Object 'System.Windows.Forms.Label'
	$textBox1 = New-Object 'System.Windows.Forms.TextBox'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$button1_Click={
		#TODO: Place custom script here
		$users = New-Object System.Collections.ArrayList
		if(!($textbox1.Text)) {
						$userinfo = Get-aduser -ErrorAction Stop | select name,SAMAccountName
					}
					else {
						$userinfo = Get-aduser $textbox1.Text -ErrorAction Stop | select Name,SAMAccountName
					}
					if($userinfo.count) {
						$users.addrange($userinfo)
					}
					else {
						$users.Add($userinfo)
					}
					
					$datagridview1.DataSource = $users
					$form1.refresh()
					$statusbar1.Text = ""
					}
				
	
	$button2_Click={
		#TODO: Place custom script here
		#Hide from GAL and set Description
	"Account is hidden"
	$id = ""
	$id = $dataGridView1.SelectedCells[0].Value.ToString()
	Set-ADUser -Identity  $id  -ErrorAction Stop -Description "TERM $(Get-Date)"
	Set-ADUser -Identity $id  -ErrorAction Stop -Replace @{msExchHideFromAddressLists="TRUE"}
	
	#Disable the account
	"Account is disabled"
	Disable-ADAccount -Identity $id   -ErrorAction Stop
	
	#Clear Manager field
	Set-aduser -Identity $id -ErrorAction Stop -manager $null
	
	#Move the account
	"Account is moved to the appropriate OU"
	Get-ADUser -Identity $id  -ErrorAction Stop | Move-ADObject -TargetPath "ou=disabled accounts,dc=difc,dc=root01,dc=org"
	"Account is disabled and moved"
	Set-ADAccountPassword -identity -Identity $id   -ErrorAction Stop -newpassword (convertto-securestring 'P@$$word1' -asplaintext -force) -Reset 	
	$statusbar1.Text = "Update $id "
	$textbox1.Text=""
	$form1.refresh()
	
	}
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$button2.remove_Click($button2_Click)
			$button1.remove_Click($button1_Click)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form1
	#
	$form1.Controls.Add($statusBar1)
	$form1.Controls.Add($button2)
	$form1.Controls.Add($dataGridView1)
	$form1.Controls.Add($button1)
	$form1.Controls.Add($label1)
	$form1.Controls.Add($textBox1)
	$form1.ClientSize = '428, 259'
	$form1.Name = "form1"
	$form1.Text = "Terminate User"
	#
	# statusBar1
	#
	$statusBar1.Location = '0, 237'
	$statusBar1.Name = "statusBar1"
	$statusBar1.Size = '428, 22'
	$statusBar1.TabIndex = 5
	#
	# button2
	#
	$button2.Location = '33, 174'
	$button2.Name = "button2"
	$button2.Size = '196, 54'
	$button2.TabIndex = 4
	$button2.Text = "TERMINATE"
	$button2.UseVisualStyleBackColor = $True
	$button2.add_Click($button2_Click)
	#
	# dataGridView1
	#
	$dataGridView1.AllowUserToAddRows = $False
	$dataGridView1.AllowUserToResizeRows = $False
	$dataGridView1.Anchor = 'Top, Bottom, Left, Right'
	$dataGridView1.AutoSizeColumnsMode = 'Fill'
	$dataGridView1.BackgroundColor = 'ActiveCaptionText'
	$dataGridView1.Location = '33, 74'
	$dataGridView1.MultiSelect = $False
	$dataGridView1.Name = "dataGridView1"
	$dataGridView1.ReadOnly = $True
	$dataGridView1.RowHeadersVisible = $False
	$dataGridView1.SelectionMode = 'FullRowSelect'
	$dataGridView1.ShowEditingIcon = $False
	$dataGridView1.Size = '368, 75'
	$dataGridView1.TabIndex = 3
	#
	# button1
	#
	$button1.FlatStyle = 'Popup'
	$button1.Location = '302, 36'
	$button1.Name = "button1"
	$button1.Size = '75, 23'
	$button1.TabIndex = 2
	$button1.Text = "Search"
	$button1.UseVisualStyleBackColor = $True
	$button1.add_Click($button1_Click)
	#
	# label1
	#
	$label1.Location = '33, 13'
	$label1.Name = "label1"
	$label1.Size = '100, 23'
	$label1.TabIndex = 1
	$label1.Text = "Enter Username"
	#
	# textBox1
	#
	$textBox1.Location = '33, 36'
	$textBox1.Name = "textBox1"
	$textBox1.Size = '240, 20'
	$textBox1.TabIndex = 0
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$form1.add_FormClosed($Form_Cleanup_FormClosed)
	#Show the Form
	return $form1.ShowDialog()

} #End Function

#Call the form
Call-term-user2014-2_pff | Out-Null

Open in new window

0
 
LVL 14

Author Comment

by:Ben Hart
ID: 39942106
Eureka!

very nicely done.. i had suspicions that the arguments for my set-aduser lines were indeed incorrect.  That's what I get for trying to use code that I don't understand yet ')

Much obliged.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question