Add 'ADUser_GUI.ps1'
Signed-off-by: Tre Hayes <thayes@noreply.homeserver.local>
This commit is contained in:
parent
ea062111eb
commit
06ae485c1c
327
ADUser_GUI.ps1
Normal file
327
ADUser_GUI.ps1
Normal file
@ -0,0 +1,327 @@
|
||||
Import-Module -Name ".\ADUser_GUI-Functions.ps1"
|
||||
Import-Module -Name ".\NewUser_Creation.ps1"
|
||||
|
||||
#Add required assemblies
|
||||
Add-Type -AssemblyName PresentationFramework, Microsoft.VisualBasic, System.Windows.Forms, System.Drawing
|
||||
[System.Windows.Forms.Application]::EnableVisualStyles()
|
||||
|
||||
$departments = Import-Csv -Path '.\SEVPlist.csv' | Sort-Object 'DepartmentName'
|
||||
$jobs = Import-Csv -Path '.\SEJobCode.txt' -Delimiter ';' | Sort-Object 'Lawson Job Description'
|
||||
$label_Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 12, [System.Drawing.FontStyle]::Bold)
|
||||
|
||||
#Create Form
|
||||
$main_Form = New-Object System.Windows.Forms.Form
|
||||
$main_Form.Text = 'Build Active Directory User'
|
||||
$main_Form.Size = New-Object System.Drawing.Size(600, 400)
|
||||
$main_Form.MaximizeBox = $false
|
||||
$main_Form.TopMost = $true
|
||||
$main_Form.StartPosition = 'CenterScreen'
|
||||
|
||||
#manualBuild_RadioButton Properties
|
||||
$manualBuild_RadioButton = New-Object System.Windows.Forms.RadioButton
|
||||
$manualBuild_RadioButton.Text = 'Manually Build'
|
||||
$manualBuild_RadioButton.Location = New-Object System.Drawing.Size(10,10)
|
||||
$manualBuild_RadioButton.AutoSize = $true
|
||||
$manualBuild_RadioButton.Checked = $true
|
||||
$manualBuild_RadioButton.add_Click({
|
||||
manualBuild($main_Form.Controls)
|
||||
validate-RadioButtons
|
||||
})
|
||||
#$manualBuild_RadioButton.Name = 'Manually Build'
|
||||
$main_Form.Controls.Add($manualBuild_RadioButton)
|
||||
|
||||
#csvBuild_RadioButton
|
||||
$csvBuild_RadioButton = New-Object System.Windows.Forms.RadioButton
|
||||
$csvBuild_RadioButton.Text = 'Build from CSV'
|
||||
$csvBuild_RadioButton.Location = New-Object System.Drawing.Size($manualBuild_RadioButton.Bounds.Right, $manualBuild_RadioButton.Location.Y)
|
||||
$csvBuild_RadioButton.AutoSize = $true
|
||||
$csvBuild_RadioButton.Checked = $false
|
||||
$csvBuild_RadioButton.add_Click({
|
||||
csvBuild($main_Form.Controls)
|
||||
validate-RadioButtons
|
||||
})
|
||||
$main_Form.Controls.Add($csvBuild_RadioButton)
|
||||
|
||||
#empID_Label Properties
|
||||
$empID_Label = New-Object System.Windows.Forms.Label
|
||||
$empID_Label.Font = $label_Font
|
||||
$empID_Label.Text = 'Employee ID:'
|
||||
$empID_Label.Location = New-Object System.Drawing.Size(10,50)
|
||||
$empID_Label.AutoSize = $true
|
||||
$empID_Label.Enabled = $false
|
||||
$empID_Label.Visible = $false
|
||||
$main_Form.Controls.Add($empID_Label)
|
||||
#empID_TextBox Properties
|
||||
$empID_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$empID_TextBox.Location = New-Object System.Drawing.Size($empID_Label.Location.X, $empID_Label.Bounds.Bottom)
|
||||
$empID_TextBox.Width = $empID_Label.Width
|
||||
$empID_TextBox.AutoSize = $true
|
||||
$empID_TextBox.MaxLength = 6
|
||||
$empID_TextBox.AcceptsTab = $true
|
||||
$empID_TextBox.Enabled = $false
|
||||
$empID_TextBox.Visible = $false
|
||||
$empID_TextBox.Add_KeyDown({
|
||||
select-All($_)
|
||||
})
|
||||
$empID_TextBox.Add_TextChanged({
|
||||
validate-BoxesAndCombos
|
||||
})
|
||||
$main_Form.Controls.Add($empID_TextBox)
|
||||
|
||||
#fName_Label Properties
|
||||
$fName_Label = New-Object System.Windows.Forms.Label
|
||||
$fName_Label.Font = $label_Font
|
||||
$fName_Label.Text = 'First Name:'
|
||||
$fName_Label.Location = New-Object System.Drawing.Size($empID_TextBox.Location.X,($empID_TextBox.Bounds.Bottom + 5))
|
||||
$fName_Label.AutoSize = $true
|
||||
$fName_Label.Enabled = $false
|
||||
$fName_Label.Visible = $false
|
||||
$main_Form.Controls.Add($fName_Label)
|
||||
#fName_TextBox Properties
|
||||
$fName_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$fName_TextBox.Location = New-Object System.Drawing.Size($fName_Label.Location.X, $fName_Label.Bounds.Bottom)
|
||||
$fName_TextBox.Width = $fName_Label.Width
|
||||
$fName_TextBox.AutoSize = $true
|
||||
$fName_TextBox.AcceptsTab = $true
|
||||
$fName_TextBox.Enabled = $false
|
||||
$fName_TextBox.Visible = $false
|
||||
$fName_TextBox.Add_KeyDown({
|
||||
select-All($_)
|
||||
})
|
||||
$fName_TextBox.Add_TextChanged({
|
||||
validate-BoxesAndCombos
|
||||
})
|
||||
$main_Form.Controls.Add($fName_TextBox)
|
||||
|
||||
#mInitial_Label Properties
|
||||
$mInitial_Label = New-Object System.Windows.Forms.Label
|
||||
$mInitial_Label.Font = $label_Font
|
||||
$mInitial_Label.Text = 'MI:'
|
||||
$mInitial_Label.Location = New-Object System.Drawing.Size(($fName_Label.Bounds.Right + 20),$fName_Label.Location.Y)
|
||||
$mInitial_Label.AutoSize = $true
|
||||
$mInitial_Label.Enabled = $false
|
||||
$mInitial_Label.Visible = $false
|
||||
$main_Form.Controls.Add($mInitial_Label)
|
||||
#mInitial_TextBox Properties
|
||||
$mInitial_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$mInitial_TextBox.Location = New-Object System.Drawing.Size(($mInitial_Label.Location.X), $mInitial_Label.Bounds.Bottom)
|
||||
$mInitial_TextBox.Width = $mInitial_Label.Width
|
||||
$mInitial_TextBox.MaxLength = 1
|
||||
$mInitial_TextBox.CharacterCasing = 'Upper'
|
||||
$mInitial_TextBox.AutoSize = $true
|
||||
$mInitial_TextBox.AcceptsTab = $true
|
||||
$mInitial_TextBox.Enabled = $false
|
||||
$mInitial_TextBox.Visible = $false
|
||||
$mInitial_TextBox.Add_KeyDown({
|
||||
select-All($_)
|
||||
})
|
||||
$main_Form.Controls.Add($mInitial_TextBox)
|
||||
|
||||
#lName_Label Properties
|
||||
$lName_Label = New-Object System.Windows.Forms.Label
|
||||
$lName_Label.Font = $label_Font
|
||||
$lName_Label.Text = 'Last Name:'
|
||||
$lName_Label.Location = New-Object System.Drawing.Size(($mInitial_Label.Bounds.Right + 20),$mInitial_Label.Location.Y)
|
||||
$lName_Label.AutoSize = $true
|
||||
$lName_Label.Enabled = $false
|
||||
$lName_Label.Visible = $false
|
||||
$main_Form.Controls.Add($lName_Label)
|
||||
#lName_TextBox Properties
|
||||
$lName_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$lName_TextBox.Location = New-Object System.Drawing.Size(($lName_Label.Location.X), $lName_Label.Bounds.Bottom)
|
||||
$lName_TextBox.Width = $lName_Label.Width
|
||||
$lName_TextBox.AutoSize = $true
|
||||
$lName_TextBox.AcceptsTab = $true
|
||||
$lName_TextBox.Enabled = $false
|
||||
$lName_TextBox.Visible = $false
|
||||
$lName_TextBox.Add_KeyDown({
|
||||
select-All($_)
|
||||
})
|
||||
$lName_TextBox.Add_TextChanged({
|
||||
validate-BoxesAndCombos
|
||||
})
|
||||
$main_Form.Controls.Add($lName_TextBox)
|
||||
|
||||
#nickName_Label Properties
|
||||
$nickName_Label = New-Object System.Windows.Forms.Label
|
||||
$nickName_Label.Font = $label_Font
|
||||
$nickName_Label.Text = 'NickName:'
|
||||
$nickName_Label.Location = New-Object System.Drawing.Size(($lName_Label.Bounds.Right + 20),$lName_Label.Location.Y)
|
||||
$nickName_Label.AutoSize = $true
|
||||
$nickName_Label.Enabled = $false
|
||||
$nickName_Label.Visible = $false
|
||||
$main_Form.Controls.Add($nickName_Label)
|
||||
#nickName_TextBox Properties
|
||||
$nickName_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$nickName_TextBox.Location = New-Object System.Drawing.Size(($nickName_Label.Location.X), $nickName_Label.Bounds.Bottom)
|
||||
$nickName_TextBox.Width = $lName_Label.Width
|
||||
$nickName_TextBox.AutoSize = $true
|
||||
$nickName_TextBox.AcceptsTab = $true
|
||||
$nickName_TextBox.Enabled = $false
|
||||
$nickName_TextBox.Visible = $false
|
||||
$nickName_TextBox.Add_KeyDown({
|
||||
select-All($_)
|
||||
})
|
||||
$main_Form.Controls.Add($nickName_TextBox)
|
||||
|
||||
#deptCode_Label Properties
|
||||
$deptCode_Label = New-Object System.Windows.Forms.Label
|
||||
$deptCode_Label.Font = $label_Font
|
||||
$deptCode_Label.Text = 'Dept Code:'
|
||||
$deptCode_Label.Location = New-Object System.Drawing.Size($fName_TextBox.Location.X,($fName_TextBox.Bounds.Bottom + 5))
|
||||
$deptCode_Label.AutoSize = $true
|
||||
$deptCode_Label.Enabled = $false
|
||||
$deptCode_Label.Visible = $false
|
||||
$main_Form.Controls.Add($deptCode_Label)
|
||||
#deptCode_TextBox Properties
|
||||
$deptCode_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$deptCode_TextBox.Location = New-Object System.Drawing.Size($deptCode_Label.Location.X, $deptCode_Label.Bounds.Bottom)
|
||||
$deptCode_TextBox.Width = $deptCode_Label.Width
|
||||
$deptCode_TextBox.AutoSize = $true
|
||||
$deptCode_TextBox.AcceptsTab = $true
|
||||
$deptCode_TextBox.Enabled = $false
|
||||
$deptCode_TextBox.Visible = $false
|
||||
$main_Form.Controls.Add($deptCode_TextBox)
|
||||
|
||||
#deptName_Label Properties
|
||||
$deptName_Label = New-Object System.Windows.Forms.Label
|
||||
$deptName_Label.Font = $label_Font
|
||||
$deptName_Label.Text = 'Department Name:'
|
||||
$deptName_Label.Location = New-Object System.Drawing.Size(($deptCode_Label.Bounds.Right + 20),$deptCode_Label.Location.Y)
|
||||
$deptName_Label.AutoSize = $true
|
||||
$deptName_Label.Enabled = $false
|
||||
$deptName_Label.Visible = $false
|
||||
$main_Form.Controls.Add($deptName_Label)
|
||||
#deptName_ComboBox Properties
|
||||
$deptName_ComboBox = New-Object System.Windows.Forms.ComboBox
|
||||
$deptName_ComboBox.Location = New-Object System.Drawing.Size(($deptName_Label.Location.X), $deptName_Label.Bounds.Bottom)
|
||||
$deptName_ComboBox.Width = $deptName_Label.Width + 150
|
||||
$deptName_ComboBox.AutoSize = $true
|
||||
$deptName_ComboBox.DropDownStyle = 'DropDown'
|
||||
$deptName_ComboBox.AutoCompleteSource = 'ListItems'
|
||||
$deptName_ComboBox.AutoCompleteMode = 'Append'
|
||||
$deptName_ComboBox.Items.Add('')
|
||||
$deptName_ComboBox.Items.AddRange($departments.'DepartmentName')
|
||||
$deptName_ComboBox.Enabled = $false
|
||||
$deptName_ComboBox.Visible = $false
|
||||
$deptName_ComboBox.Add_SelectedValueChanged({
|
||||
set-DeptCode($deptName_ComboBox.Text)
|
||||
})
|
||||
$deptName_ComboBox.Add_TextChanged({
|
||||
validate-BoxesAndCombos
|
||||
})
|
||||
$main_Form.Controls.Add($deptName_ComboBox)
|
||||
|
||||
#jobCode_Label Properties
|
||||
$jobCode_Label = New-Object System.Windows.Forms.Label
|
||||
$jobCode_Label.Font = $label_Font
|
||||
$jobCode_Label.Text = 'Job Code:'
|
||||
$jobCode_Label.Location = New-Object System.Drawing.Size($deptCode_TextBox.Location.X,($deptCode_TextBox.Bounds.Bottom + 5))
|
||||
$jobCode_Label.AutoSize = $true
|
||||
$jobCode_Label.Enabled = $false
|
||||
$jobCode_Label.Visible = $false
|
||||
$main_Form.Controls.Add($jobCode_Label)
|
||||
#jobCode_TextBox Properties
|
||||
$jobCode_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$jobCode_TextBox.Location = New-Object System.Drawing.Size($jobCode_Label.Location.X, $jobCode_Label.Bounds.Bottom)
|
||||
$jobCode_TextBox.Width = $deptCode_TextBox.Width
|
||||
$jobCode_TextBox.AutoSize = $true
|
||||
$jobCode_TextBox.AcceptsTab = $true
|
||||
$jobCode_TextBox.Enabled = $false
|
||||
$jobCode_TextBox.Visible = $false
|
||||
$main_Form.Controls.Add($jobCode_TextBox)
|
||||
|
||||
#jobTitle_Label Properties
|
||||
$jobTitle_Label = New-Object System.Windows.Forms.Label
|
||||
$jobTitle_Label.Font = $label_Font
|
||||
$jobTitle_Label.Text = 'Job Title:'
|
||||
$jobTitle_Label.Location = New-Object System.Drawing.Size($deptName_Label.Location.X,$jobCode_Label.Location.Y)
|
||||
$jobTitle_Label.AutoSize = $true
|
||||
$jobTitle_Label.Enabled = $false
|
||||
$jobTitle_Label.Visible = $false
|
||||
$main_Form.Controls.Add($jobTitle_Label)
|
||||
#jobTitle_ComboBox Properties
|
||||
$jobTitle_ComboBox = New-Object System.Windows.Forms.ComboBox
|
||||
$jobTitle_ComboBox.Location = New-Object System.Drawing.Size($deptName_Label.Location.X, $jobTitle_Label.Bounds.Bottom)
|
||||
$jobTitle_ComboBox.Width = $deptName_ComboBox.Width
|
||||
$jobTitle_ComboBox.AutoSize = $true
|
||||
$jobTitle_ComboBox.DropDownStyle = 'DropDown'
|
||||
$jobTitle_ComboBox.AutoCompleteSource = 'ListItems'
|
||||
$jobTitle_ComboBox.AutoCompleteMode = 'Append'
|
||||
$jobTitle_ComboBox.Items.Add('')
|
||||
$jobTitle_ComboBox.Items.AddRange($jobs.'Lawson Job Description')
|
||||
$jobTitle_ComboBox.Enabled = $false
|
||||
$jobTitle_ComboBox.Visible = $false
|
||||
$jobTitle_ComboBox.Add_SelectedValueChanged({
|
||||
set-JobCode($jobTitle_ComboBox.Text)
|
||||
})
|
||||
$jobTitle_ComboBox.Add_TextChanged({
|
||||
validate-BoxesAndCombos
|
||||
})
|
||||
$main_Form.Controls.Add($jobTitle_ComboBox)
|
||||
|
||||
#vp_Label Properties
|
||||
$vp_Label = New-Object System.Windows.Forms.Label
|
||||
$vp_Label.Font = $label_Font
|
||||
$vp_Label.Text = 'Vice President:'
|
||||
$vp_Label.Location = New-Object System.Drawing.Size($jobCode_TextBox.Location.X,($jobCode_TextBox.Bounds.Bottom + 5))
|
||||
$vp_Label.AutoSize = $true
|
||||
$vp_Label.Enabled = $false
|
||||
$vp_Label.Visible = $false
|
||||
$main_Form.Controls.Add($vp_Label)
|
||||
#vp_TextBox Properties
|
||||
$vp_TextBox = New-Object System.Windows.Forms.TextBox
|
||||
$vp_TextBox.Location = New-Object System.Drawing.Size($vp_Label.Location.X, $vp_Label.Bounds.Bottom)
|
||||
$vp_TextBox.Width = $vp_Label.Width
|
||||
$vp_TextBox.AutoSize = $true
|
||||
$vp_TextBox.AcceptsTab = $true
|
||||
$vp_TextBox.Enabled = $false
|
||||
$vp_TextBox.Visible = $false
|
||||
$main_Form.Controls.Add($vp_TextBox)
|
||||
|
||||
|
||||
#csvPath_Label Properties
|
||||
$csvPath_Label = New-Object System.Windows.Forms.Label
|
||||
$csvPath_Label.Font = $label_Font
|
||||
$csvPath_Label.Text = 'This will import users from a CSV located at .\NewUser_Test.csv'
|
||||
$csvPath_Label.Dock = 'Fill'
|
||||
$csvPath_Label.TextAlign = 'MiddleCenter'
|
||||
$csvPath_Label.AutoSize = $false
|
||||
$csvPath_Label.Enabled = $false
|
||||
$csvPath_Label.Visible = $false
|
||||
$main_Form.Controls.Add($csvPath_Label)
|
||||
|
||||
#build_User Properties
|
||||
$build_User_Button = New-Object System.Windows.Forms.Button
|
||||
$build_User_Button.AutoSize = $true
|
||||
$build_User_Button.Text = 'Build User(s)'
|
||||
$build_User_Button.Enabled = $false
|
||||
$build_User_Button.Dock = 'Bottom'
|
||||
$build_User_Button.add_Click({
|
||||
if ($csvBuild_RadioButton.Checked) {
|
||||
Build-MultiADUser($departments)
|
||||
}
|
||||
else {
|
||||
$user_Object = [PSCustomObject]@{
|
||||
emp_ID = $empID_TextBox.Text
|
||||
first_Name = $fName_TextBox.Text
|
||||
last_Name = $lName_TextBox.Text
|
||||
middle_name = $mInitial_TextBox.Text
|
||||
nick_name = $nickName_TextBox.Text
|
||||
dept_Code = $deptCode_TextBox.Text
|
||||
department_name = $deptName_ComboBox.Text
|
||||
job_Title = $jobTitle_ComboBox.Text
|
||||
vice_President = foreach ($dept in $departments) {
|
||||
switch ($deptName_ComboBox.Text) {
|
||||
$dept.'DepartmentName' { $dept.'VP EmpID' }
|
||||
'' { '' }
|
||||
}
|
||||
}
|
||||
}
|
||||
Build-ADUser -User $user_Object
|
||||
}
|
||||
})
|
||||
$main_Form.Controls.Add($build_User_Button)
|
||||
|
||||
$main_Form.TopMost = $true
|
||||
$main_Form.ShowDialog() | Out-Null
|
Loading…
Reference in New Issue
Block a user