视频的容积 发表于 2018-9-2 10:24:57

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

cls  
Import-Module ActiveDirectory
  
::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


页: [1]
查看完整版本: 带GUI界面的重置域账号密码PowerShell脚本