繁体   English   中英

Powershell广告重置实用程序

[英]Powershell Ad Reset Utility

希望获得有关此AD密码重置实用程序的帮助。 我正在使用.Net对象构建表单,但是当我执行脚本时,它将运行set-adaccountpassword cmdlet,然后才有机会从下拉列表中选择密码和用户名的变量值。 我似乎无法正确获得代码的执行顺序。 请帮忙!

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Visualbasic')  

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(600,275)
$form.Name="UCEDC Password Reset"  
$form.BackColor="lightGreen"
$form.Text="Company Password Reset Utility"

############################################## Start functions

#$computer=$DropDownBox.SelectedItem.ToString() #populate the var with the value you selected

############################################## end functions

############################################## Start drop down boxes

$DropDownBox = New-Object System.Windows.Forms.ComboBox
$DropDownBox.Location = New-Object System.Drawing.Size(20,50) 
$DropDownBox.Size = New-Object System.Drawing.Size(180,20) 
$DropDownBox.DropDownHeight = 200 
$Form.Controls.Add($DropDownBox) 

$wksList=@(get-aduser -filter *| select-object -ExpandProperty samaccountname)

foreach ($wks in $wksList) {
                      $DropDownBox.Items.Add($wks)
                              } #end foreach
$passworchange=$DropDownBox.SelectedItem

############################################## end drop down boxes

$Button = New-Object System.Windows.Forms.Button 
$Button.Location = New-Object System.Drawing.Size(400,30) 
$Button.Size = New-Object System.Drawing.Size(110,80) 
$Button.Text = "Reset Password"

$button.add_click({[Microsoft.VisualBasic.interaction]::inputbox("Enter a Password","Password",$passworchange) })

##$Button.Add_Click({procInfo})

$Form.Controls.Add($Button) 

Set-ADAccountPassword -Identity $username -NewPassword $passworchange

############################################## Start text fields

$outputBox = New-Object System.Windows.Forms.TextBox 
$outputBox.Location = New-Object System.Drawing.Size(10,150) 
$outputBox.Size = New-Object System.Drawing.Size(565,200) 
$outputBox.MultiLine = $True 
$outputBox.ScrollBars = "Vertical" 
$outputBox.text= $passworchange
$Form.Controls.Add($outputBox) 

############################################## end text fields

############################################## Start buttons

############################################## end buttons

$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

问题是您需要将Set-ADAccountPassword行放在ScriptBlock中,以便单击按钮,但是在提示输入密码之后。

$button.add_click({$PasswordChange = [Microsoft.VisualBasic.interaction]::inputbox("Enter a Password","Password","Change Me"); Set-ADAccountPassword -Identity $username -NewPassword $passwordchange})

一个更好的主意可能是生成一个随机密码,将用户密码设置为该密码,然后告知他们该密码是什么。 我过去使用过的东西是:

#Load the [System.Web] assembly so we can generate passwords later on
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")|out-null
#Generate a 15 character complex password, with between 3 and 10 non-alpha characters
[string]$Password = [System.Web.Security.Membership]::GeneratePassword(15,(get-random -min 3 -max 10))
$Password|CLIP

这会将$Password设置为随机生成的密码,并将该密码复制到剪贴板(以防您需要通过电子邮件发送给某人或将其粘贴到电子表格等中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM