Here's a script that creates a GUI for creating an Active Directory (AD) user using PowerShell:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $form = New-Object System.Windows.Forms.Form $form.Text = "Create AD User" $form.Size = New-Object System.Drawing.Size(400,300) $form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen $UsernameLabel = New-Object System.Windows.Forms.Label $UsernameLabel.Text = "Username:" $UsernameLabel.Size = New-Object System.Drawing.Size(70,20) $UsernameLabel.Location = New-Object System.Drawing.Point(30,50) $UsernameTextBox = New-Object System.Windows.Forms.TextBox $UsernameTextBox.Size = New-Object System.Drawing.Size(200,20) $UsernameTextBox.Location = New-Object System.Drawing.Point(120,50) $PasswordLabel = New-Object System.Windows.Forms.Label $PasswordLabel.Text = "Password:" $PasswordLabel.Size = New-Object System.Drawing.Size(70,20) $PasswordLabel.Location = New-Object System.Drawing.Point(30,100) $PasswordTextBox = New-Object System.Windows.Forms.TextBox $PasswordTextBox.Size = New-Object System.Drawing.Size(200,20) $PasswordTextBox.Location = New-Object System.Drawing.Point(120,100) $PasswordTextBox.PasswordChar = "*" $Button = New-Object System.Windows.Forms.Button $Button.Text = "Create User" $Button.Size = New-Object System.Drawing.Size(100,20) $Button.Location = New-Object System.Drawing.Point(150,150) $Button.Add_Click({ $Username = $UsernameTextBox.Text $Password = $PasswordTextBox.Text $SecurePassword = ConvertTo-SecureString -AsPlainText $Password -Force New-ADUser -Name $Username -AccountPassword $SecurePassword [System.Windows.Forms.MessageBox]::Show("User created successfully.") }) $form.Controls.Add($UsernameLabel) $form.Controls.Add($UsernameTextBox) $form.Controls.Add($PasswordLabel) $form.Controls.Add($PasswordTextBox) $form.Controls.Add($Button) $form.ShowDialog()
Note: This script uses Windows Forms to create a GUI that allows you to input a username and password, and then creates an AD user with that information. Note that you will need to have the Active Directory module for Windows PowerShell installed on the machine running this script.
No comments:
Post a Comment