Here's a PowerShell script that creates a Windows Form with a user input box and a button for resetting an Active Directory user password:
# Load the System.Windows.Forms assembly
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
# Create the form
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(300, 200)
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
# Create the user input box
$input = New-Object System.Windows.Forms.TextBox
$input.Size = New-Object System.Drawing.Size(200, 20)
$input.Location = New-Object System.Drawing.Point(50, 50)
$form.Controls.Add($input)
# Create the button
$button = New-Object System.Windows.Forms.Button
$button.Text = "Reset Password"
$button.Size = New-Object System.Drawing.Size(100, 23)
$button.Location = New-Object System.Drawing.Point(100, 100)
$button.Add_Click({
# Get the user name from the input box
$username = $input.Text
# Reset the password for the specified user
Set-ADAccountPassword -Identity $username -Reset
# Show a message box with the result
[System.Windows.Forms.MessageBox]::Show("Password reset for user $username.", "Password Reset", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
})
$form.Controls.Add($button)
# Show the form
$form.ShowDialog()
System.Windows.Forms
assembly to create a form with a text box for entering the user name and a button for resetting the password. The user name is entered in the text box, and the password is reset when the button is clicked. The Set-ADAccountPassword
cmdlet is used to reset the password, and a message box is displayed with the result. Note that this script requires that the Active Directory module for Windows PowerShell is installed on the system where the script is run.
No comments:
Post a Comment