带GUI界面的重置域账号密码PowerShell脚本

闲来无事,写了一脚本玩……

重置的密码为Abc+域用户电话号码^.^

    $pw="Abc+"+$tel
    $pw=ConvertTo-SecureString $pw -AsPlainText -Force

以下为完整代码:

cls
Import-Module ActiveDirectory
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null 


$main = New-Object System.Windows.Forms.Form 
$btnSubmit1 = New-Object System.Windows.Forms.Button
$btnSubmit2  = New-Object System.Windows.Forms.Button
$txtbox = New-Object System.Windows.Forms.TextBox

$main_click = {
        $userName = $txtbox.Text
    $tel=Get-ADUser -Identity $userName -Properties *
    $tel=$tel.telephoneNumber
    $pw="Abc+"+$tel
    $pw=ConvertTo-SecureString $pw -AsPlainText -Force
    set-ADAccountPassword -Identity $userName -NewPassword $pw -Reset
}    
$main_close = {
    Remove-Module ActiveDirectory
    $main.Close()
}

$main.Width = 300
$main.Height = 100
$main.Text = 'ResetPassword Tool'

$txtbox.width = 130
$txtbox.Height = 25
$txtbox.Location = New-Object System.Drawing.Point(6,19)
$txtbox.Name = 'boxname'

$btnSubmit1.Location = New-Object System.Drawing.Point(140,17)
$btnSubmit1.Name = "btnSubmit1"
$btnSubmit1.Size = '65, 25'
$btnSubmit1.Text = "重置"
$btnSubmit1.add_Click($main_click) | Out-Null

$btnSubmit2.Location = New-Object System.Drawing.Point(210,17)
$btnSubmit2.Name = "btnSubmit2"
$btnSubmit2.Size = '65, 25'
$btnSubmit2.Text = "退出"
$btnSubmit2.add_Click($main_close) | Out-Null



$main.Controls.Add($txtbox)
$main.Controls.Add($btnSubmit1)
$main.Controls.Add($btnSubmit2)
$main.ShowDialog() | Out-Null


你可能感兴趣的:(password,powershell,ActiveDirectory)