One of the my blog reader, came across one of the article written on generating random password gui using powershell by me, and he contacted me as he wanted a small help on creating one GUI utility ADUser reset password. Below are the detailed information he provided in the email what exactly he needed.

Allow you to enter a 4 character user ID (their AD account) and the gui will reset the password with 15 random characters. eg. userid = PATR Allow you to enter a 9 character user ID (their admin account) and the gui will reset the password with 20 random characters. eg userid = PATRAdmin Once the Helpdesk member enters the user ID, the GUI will reset the password with 15 or 20 and check the change password on next login. It will also display the password and allow them to copy it.

I took my little time and build this small GUI script for him, This script is completely built using Visual studio and used OS Windows 10. I am using Windows 2016 Active directory module to reset password of ad user. The user didn't ask for Manager/TL automated password email send function, but I added it to this utility as a extra feature. There are two files required, first is conf.ini file, contents are as below, You can modify the content as per your need. Ps1 file also listed below. Before running script you follow my earlier related blogs.

Installing, importing and using any module in powershell

Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled

[Emailserver]

From=noreply_helpdesk@vcloud-lab.com

SMTPServer=192.168.34.11

Port=25

Once launched the script, password reset successful, and in the last password is sent, I am receiving it in email with all the information, I hope this will be helpful to you as well.

Download this script from here, it is also available on github.com.

<# .NOTES -------------------------------------------------------------------------------- Code generated by: Visual Studio Created on: 4/17/2018 4:57 AM Generated by: http://vcloud-lab.com Written by: Kunal Udapi Tested on: Windows 10 Rsat tool Windows 2016 Server - Active Directory -------------------------------------------------------------------------------- .DESCRIPTION GUI script generated using Visual Studio 2015 #> #region Add-Type -AssemblyName PresentationFramework [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Windows.Forms.Application]::EnableVisualStyles() function New-Password { #requires -version 4 <# .SYNOPSIS This script Generates a random strong password. .DESCRIPTION The New-RandomPassword generates a random strong password from mix of capital letters, small letters, symbols (Special Characters) and numbers, All the parameter only accept numeric values. .PARAMETER PasswordLength PasswordLength parameter prompts for password length, If this parameter is not defined by default it creates 12 digit mix characters. This parameter cannot be used with other SmallLetter, Capitalletter, Symbol and Number. .PARAMETER SmallLetter This syntax is optional and cannot be used with PasswordLength. If you use, for example 5 value, Password will include 5 random small letter characters (a-z) in the password. .PARAMETER CapitalLetter This syntax is optional and cannot be used with PasswordLength. If you use for example 5 value, you will find 5 random capital letters (A-Z) in the password. .PARAMETER Number By Default value is 0, and do not require to mention, If you use for example 2 value for this syntax, you will find 2 random numbers (0-9) in the password. .PARAMETER Symbol By Default value is 0, and do not require to mention, If you use for example 2 value for this syntax, you will find 2 random numbers (! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ { | } ~) in the password. .INPUTS [System.int] .OUTPUTS [System.String] [System.Management.Automation.PSCustomObject] .NOTES Script Version: 2.0 Author: Kunal Udapi Creation Date: 20 September 2017 Purpose/Change: Get windows office and OS licensing information. Useful URLs: http://kunaludapi.blogspot.in/2013/11/generate-random-password-powershell.html http://vcloud-lab.com/entries/powershell/microsoft-powershell-generate-random-anything-filename--temppath--guid--password- OS Version: Windows 8.1 Powershell Version: Powershell V5.1 Desktop .EXAMPLE PS C:\>.\New-RandomPassword.ps1 It generated strong random 12 digit password with defination Character, Phonetic and character type .EXAMPLE PS C:\>.\New-RandomPassword.ps1 -PasswordLength 6 Character Phonetic Type --------- -------- ---- 3 Three Number [ Opening bracket Symbol 6 Six Number 4 Four Number w Whiskey Small Letter D Delta Capital Letter 3[64wD With the parameter passwordLength, it generates 6 digit random password as shown results. .EXAMPLE PS C:\>.\New-RandomPassword.ps1 -SmallLetter 4 -CapitalLetter 4 -Number 2 -Symbol 2 As per syntax and provided value, there will be 4 small letters, 4 capital letter , 2 numbers and 2 symbols special characters in the newly generated password. #> [CmdletBinding(SupportsShouldProcess=$True, ConfirmImpact='Medium', HelpURI='http://vcloud-lab.com', DefaultParameterSetName='Default')] Param ( [parameter(ParameterSetName = 'Default', Position=0, Mandatory=$false, ValueFromPipelineByPropertyName=$True, ValueFromPipeline=$True)] [alias('length')] [int]$PasswordLength = 12, [parameter(ParameterSetName = 'Option', Position=0, ValueFromPipelineByPropertyName=$true)] [alias('LowerCase','Small')] [int]$SmallLetter = 0, [parameter(ParameterSetName = 'Option', Position=1, ValueFromPipelineByPropertyName=$true)] [alias('UpperCase','Capital')] [int]$CapitalLetter = 0, [parameter(ParameterSetName = 'Option', Position=2, ValueFromPipelineByPropertyName=$true)] [int]$Number = 0, [parameter(ParameterSetName = 'Option', Position=3, ValueFromPipelineByPropertyName=$true)] [alias('SpecialLetter')] [int]$Symbol = 0 ) Begin { $RandomOption = @() $CompletePassword = @() $CompleteSmallPassword = @() $CompleteCapitalPassword = @() $CompleteSymbolPassword = @() $CompleteNumberPassword = @() #table $JSon = @" [ {"SrNo": "1","Number": "33","Character": "!","Phonetic": "Exclamation point","Type": "Symbol"}, {"SrNo": "2","Number": "34","Character": "\"","Phonetic": "Double quotes","Type": "Symbol"}, {"SrNo": "3","Number": "35","Character": "#","Phonetic": "Hash sign","Type": "Symbol"}, {"SrNo": "4","Number": "36","Character": "$","Phonetic": "Dollar sign","Type": "Symbol"}, {"SrNo": "5","Number": "37","Character": "%","Phonetic": "Percent sign","Type": "Symbol"}, {"SrNo": "6","Number": "38","Character": "&","Phonetic": "Ampersand","Type": "Symbol"}, {"SrNo": "7","Number": "39","Character": "'","Phonetic": "Single quote","Type": "Symbol"}, {"SrNo": "8","Number": "40","Character": "(","Phonetic": "Opening parenthesis","Type": "Symbol"}, {"SrNo": "9","Number": "41","Character": ")","Phonetic": "Closing parenthesis","Type": "Symbol"}, {"SrNo": "10","Number": "42","Character": "*","Phonetic": "Asterisk","Type": "Symbol"}, {"SrNo": "11","Number": "43","Character": "+","Phonetic": "Plus sign","Type": "Symbol"}, {"SrNo": "12","Number": "44","Character": ",","Phonetic": "Comma","Type": "Symbol"}, {"SrNo": "13","Number": "45","Character": "-","Phonetic": "Minus sign -Hyphen","Type": "Symbol"}, {"SrNo": "14","Number": "46","Character": ".","Phonetic": "Period","Type": "Symbol"}, {"SrNo": "15","Number": "47","Character": "/","Phonetic": "Slash","Type": "Symbol"}, {"SrNo": "16","Number": "58","Character": ":","Phonetic": "Colon","Type": "Symbol"}, {"SrNo": "17","Number": "59","Character": ";","Phonetic": "SemiColon","Type": "Symbol"}, {"SrNo": "18","Number": "60","Character": "<","Phonetic": "Less than sign","Type": "Symbol"}, {"SrNo": "19","Number": "61","Character": "=","Phonetic": "Equal sign","Type": "Symbol"}, {"SrNo": "20","Number": "62","Character": ">","Phonetic": "Greater than sign","Type": "Symbol"}, {"SrNo": "21","Number": "63","Character": "?","Phonetic": "Question mark","Type": "Symbol"}, {"SrNo": "22","Number": "64","Character": "@","Phonetic": "At symbol","Type": "Symbol"}, {"SrNo": "23","Number": "91","Character": "[","Phonetic": "Opening bracket","Type": "Symbol"}, {"SrNo": "24","Number": "92","Character": "\\","Phonetic": "Backslash","Type": "Symbol"}, {"SrNo": "25","Number": "93","Character": "]","Phonetic": "Closing bracket","Type": "Symbol"}, {"SrNo": "26","Number": "94","Character": "^","Phonetic": "Caret - circumflex","Type": "Symbol"}, {"SrNo": "27","Number": "95","Character": "_","Phonetic": "Underscore","Type": "Symbol"}, {"SrNo": "29","Number": "123","Character": "{","Phonetic": "Opening brace","Type": "Symbol"}, {"SrNo": "30","Number": "124","Character": "|","Phonetic": "Vertical bar","Type": "Symbol"}, {"SrNo": "31","Number": "125","Character": "}","Phonetic": "Closing brace","Type": "Symbol"}, {"SrNo": "32","Number": "126","Character": "~","Phonetic": "Equivalency sign - Tilde","Type": "Symbol"}, {"SrNo": "33","Number": "65","Character": "A","Phonetic": "Alpha ","Type": "Capital Letter"}, {"SrNo": "34","Number": "66","Character": "B","Phonetic": "Bravo ","Type": "Capital Letter"}, {"SrNo": "35","Number": "67","Character": "C","Phonetic": "Charlie ","Type": "Capital Letter"}, {"SrNo": "36","Number": "68","Character": "D","Phonetic": "Delta ","Type": "Capital Letter"}, {"SrNo": "37","Number": "69","Character": "E","Phonetic": "Echo ","Type": "Capital Letter"}, {"SrNo": "38","Number": "70","Character": "F","Phonetic": "Foxtrot ","Type": "Capital Letter"}, {"SrNo": "39","Number": "71","Character": "G","Phonetic": "Golf ","Type": "Capital Letter"}, {"SrNo": "40","Number": "72","Character": "H","Phonetic": "Hotel ","Type": "Capital Letter"}, {"SrNo": "41","Number": "73","Character": "I","Phonetic": "India ","Type": "Capital Letter"}, {"SrNo": "42","Number": "74","Character": "J","Phonetic": "Juliet ","Type": "Capital Letter"}, {"SrNo": "43","Number": "75","Character": "K","Phonetic": "Kilo ","Type": "Capital Letter"}, {"SrNo": "44","Number": "76","Character": "L","Phonetic": "Lima ","Type": "Capital Letter"}, {"SrNo": "45","Number": "77","Character": "M","Phonetic": "Mike ","Type": "Capital Letter"}, {"SrNo": "46","Number": "78","Character": "N","Phonetic": "November ","Type": "Capital Letter"}, {"SrNo": "47","Number": "79","Character": "O","Phonetic": "Oscar ","Type": "Capital Letter"}, {"SrNo": "48","Number": "80","Character": "P","Phonetic": "Papa ","Type": "Capital Letter"}, {"SrNo": "49","Number": "81","Character": "Q","Phonetic": "Quebec ","Type": "Capital Letter"}, {"SrNo": "50","Number": "82","Character": "R","Phonetic": "Romeo ","Type": "Capital Letter"}, {"SrNo": "51","Number": "83","Character": "S","Phonetic": "Sierra ","Type": "Capital Letter"}, {"SrNo": "52","Number": "84","Character": "T","Phonetic": "Tango ","Type": "Capital Letter"}, {"SrNo": "53","Number": "85","Character": "U","Phonetic": "Uniform ","Type": "Capital Letter"}, {"SrNo": "54","Number": "86","Character": "V","Phonetic": "Victor ","Type": "Capital Letter"}, {"SrNo": "55","Number": "87","Character": "W","Phonetic": "Whiskey ","Type": "Capital Letter"}, {"SrNo": "56","Number": "88","Character": "X","Phonetic": "X-Ray ","Type": "Capital Letter"}, {"SrNo": "57","Number": "89","Character": "Y","Phonetic": "Yankee ","Type": "Capital Letter"}, {"SrNo": "58","Number": "90","Character": "Z","Phonetic": "Zulu ","Type": "Capital Letter"}, {"SrNo": "59","Number": "97","Character": "a","Phonetic": "Alpha ","Type": "Small Letter"}, {"SrNo": "60","Number": "98","Character": "b","Phonetic": "Bravo ","Type": "Small Letter"}, {"SrNo": "61","Number": "99","Character": "c","Phonetic": "Charlie ","Type": "Small Letter"}, {"SrNo": "62","Number": "100","Character": "d","Phonetic": "Delta ","Type": "Small Letter"}, {"SrNo": "63","Number": "101","Character": "e","Phonetic": "Echo ","Type": "Small Letter"}, {"SrNo": "64","Number": "102","Character": "f","Phonetic": "Foxtrot ","Type": "Small Letter"}, {"SrNo": "65","Number": "103","Character": "g","Phonetic": "Golf ","Type": "Small Letter"}, {"SrNo": "66","Number": "104","Character": "h","Phonetic": "Hotel ","Type": "Small Letter"}, {"SrNo": "67","Number": "105","Character": "i","Phonetic": "India ","Type": "Small Letter"}, {"SrNo": "68","Number": "106","Character": "j","Phonetic": "Juliet ","Type": "Small Letter"}, {"SrNo": "69","Number": "107","Character": "k","Phonetic": "Kilo ","Type": "Small Letter"}, {"SrNo": "70","Number": "108","Character": "l","Phonetic": "Lima ","Type": "Small Letter"}, {"SrNo": "71","Number": "109","Character": "m","Phonetic": "Mike ","Type": "Small Letter"}, {"SrNo": "72","Number": "110","Character": "n","Phonetic": "November ","Type": "Small Letter"}, {"SrNo": "73","Number": "111","Character": "o","Phonetic": "Oscar ","Type": "Small Letter"}, {"SrNo": "74","Number": "112","Character": "p","Phonetic": "Papa ","Type": "Small Letter"}, {"SrNo": "75","Number": "113","Character": "q","Phonetic": "Quebec ","Type": "Small Letter"}, {"SrNo": "76","Number": "114","Character": "r","Phonetic": "Romeo ","Type": "Small Letter"}, {"SrNo": "77","Number": "115","Character": "s","Phonetic": "Sierra ","Type": "Small Letter"}, {"SrNo": "78","Number": "116","Character": "t","Phonetic": "Tango ","Type": "Small Letter"}, {"SrNo": "79","Number": "117","Character": "u","Phonetic": "Uniform ","Type": "Small Letter"}, {"SrNo": "80","Number": "118","Character": "v","Phonetic": "Victor ","Type": "Small Letter"}, {"SrNo": "81","Number": "119","Character": "w","Phonetic": "Whiskey ","Type": "Small Letter"}, {"SrNo": "82","Number": "120","Character": "x","Phonetic": "X-Ray ","Type": "Small Letter"}, {"SrNo": "83","Number": "121","Character": "y","Phonetic": "Yankee ","Type": "Small Letter"}, {"SrNo": "84","Number": "122","Character": "z","Phonetic": "Zulu ","Type": "Small Letter"}, {"SrNo": "85","Number": "48","Character": "0","Phonetic": "Zero","Type": "Number"}, {"SrNo": "86","Number": "49","Character": "1","Phonetic": "One","Type": "Number"}, {"SrNo": "87","Number": "50","Character": "2","Phonetic": "Two","Type": "Number"}, {"SrNo": "88","Number": "51","Character": "3","Phonetic": "Three","Type": "Number"}, {"SrNo": "89","Number": "52","Character": "4","Phonetic": "Four","Type": "Number"}, {"SrNo": "90","Number": "53","Character": "5","Phonetic": "Five","Type": "Number"}, {"SrNo": "91","Number": "54","Character": "6","Phonetic": "Six","Type": "Number"}, {"SrNo": "92","Number": "55","Character": "7","Phonetic": "Seven","Type": "Number"}, {"SrNo": "93","Number": "56","Character": "8","Phonetic": "Eight","Type": "Number"}, {"SrNo": "94","Number": "57","Character": "9","Phonetic": "Nine","Type": "Number"} ] "@ #Excluded Characters #{"SrNo": "28","Number": "96","Character": "`","Phonetic": "Grave accent","Type": "Symbol"}, #System.Security.Cryptography.RNGCryptoServiceProvider function Get-Rng { $RandomBytes = New-Object -TypeName "System.Byte[]" 4 $Random = New-Object -TypeName "System.Security.Cryptography.RNGCryptoServiceProvider" $Random.GetBytes($RandomBytes) [BitConverter]::ToInt32($RandomBytes, 0) } #function Get-Rng } #Begin Process { #tables $AlphbatesTable = $JSon | ConvertFrom-Json $SymbolTable = $AlphbatesTable | Where-Object {$_.Type -eq 'Symbol'} $CapitalLetterTable = $AlphbatesTable | Where-Object {$_.Type -eq 'Capital Letter'} $SmallLetterTable = $AlphbatesTable | Where-Object {$_.Type -eq 'Small Letter'} $NumberTable = $AlphbatesTable | Where-Object {$_.Type -eq 'Number'} switch ($PsCmdlet.ParameterSetName) { 'Default' { for ($i = 1; $i -le $PasswordLength; $i++) { $DefaultUniqueNumber = Get-Rng $PasswordHash = Get-Random -InputObject $AlphbatesTable -SetSeed $DefaultUniqueNumber $CompletePassword += $PasswordHash } #for ($i = 1; $i -le $PasswordLength; $i++) } #'Default' 'Option' { if ($SmallLetter -ne 0) { for ($sm = 1; $sm -le $SmallLetter; $sm++) { $SmallUniqueNumber = Get-Rng $CompleteSmallPassword += Get-Random -InputObject $SmallLetterTable -SetSeed $SmallUniqueNumber } #for ($sm = 1; $sm -le $SmallLetter; $sm++) } #if ($SmallLetter -ne 0) if ($CapitalLetter -ne 0) { for ($c = 1; $c -le $CapitalLetter; $c++) { $CapitalUniqueNumber = Get-Rng $CompleteCapitalPassword += Get-Random -InputObject $CapitalLetterTable -SetSeed $CapitalUniqueNumber } #for ($s = 1; $s -le $CapitalLetter; $s++) } #if ($CapitalLetter -ne 0) if ($Number -ne 0) { for ($N = 1; $N -le $Number; $N++) { $NumberUniqueNumber = Get-Rng $CompleteNumberPassword += Get-Random -InputObject $NumberTable -SetSeed $NumberUniqueNumber } #for ($s = 1; $s -le $Number; $s++) } #if ($Number -ne 0) if ($Symbol -ne 0) { for ($sy = 1; $sy -le $Symbol; $sy++) { $SymbolUniqueNumber = Get-Rng $CompleteSymbolPassword += Get-Random -InputObject $SymbolTable -SetSeed $SymbolUniqueNumber } #for ($sy = 1; $sy -le $Symbol; $sy++) } #if ($Symbol -ne 0) $RandomOption += $CompleteSmallPassword $RandomOption += $CompleteCapitalPassword $RandomOption += $CompleteNumberPassword $RandomOption += $CompleteSymbolPassword #$CompletePassword = $RandomOption | Sort-Object {Get-Random (Get-Rng)} $CompletePassword = $RandomOption | Select-Object *, @{N='Sort'; E={1..500 | Get-Random (Get-Rng)}} | Sort-Object -Property Sort } #'Option' } #switch ($PsCmdlet.ParameterSetName) } #Process End { $FinalPassword = $CompletePassword.Character -Join "" #$Info = $CompletePassword | Select-Object Character, Phonetic, Type #Write-Host ($Info | Out-String) -ForegroundColor Yellow -NoNewline $FinalPassword } #End } function Get-IniConfiguration { ############################## #.SYNOPSIS #Convert INI data information to Hashtable for splatting # #.DESCRIPTION #The Get-IniConfiguration cmdlet fetch information from .ini file, and convert it to hashtable, This Hastable can be used later further as splatting. This is best for non technical users, and don't want to make any changes to script. # #.PARAMETER File #This is a File path. Extension can be .txt, .ini, .info or any other readable ascii file is supported, Below is the example content of file related to service. #[service] #Name=LanManServer #ComputerName=Localhost # #.PARAMETER Conf #This is a paramenter block mentioned in brackets, and same name variable created for splatting ie #[service] # #.EXAMPLE #Get-IniConfiguration -File C:\temp\configuration.ini -Conf Service #Get-Service @Service # #Information is stored under $service (same name as -conf variable) # #.NOTES #http://vcloud-lab.com #Written using powershell version 5 #Script code version 1.0 ############################### [CmdletBinding()] param( [Parameter(Position=0, Mandatory=$true)] [ValidateScript({ If (Test-Path $_) { $true } else{ "Invalid path given: $_" } })] [System.String]$File = 'C:\Temp\Test.ini', [Parameter(Position=1, Mandatory=$true)] [System.String]$Conf ) $inifile = Get-Content -Path $File #-Raw -split '`r`n' $LineCounts = $iniFile.Count $ConfLineNumber = $iniFile | Select-String -Pattern "\[$Conf\]" | Select-Object -ExpandProperty LineNumber if ($ConfLineNumber -eq $null) { Write-Host "Please provide correct configuration name in -Conf parameter" -BackgroundColor DarkRed Break } $RawContext = $iniFile[$ConfLineNumber..$LineCounts] | Where-Object {$_.trim() -ne "" -and $_.trim() -notmatch "^;"} $FinalLineNumber = $RawContext | Select-String -Pattern "\[*\]" | Select-Object -First 1 -ExpandProperty LineNumber $FinalLineNumber = $FinalLineNumber - 1 if ($FinalLineNumber -ge 1) { $FinalData = $RawContext | Select-Object -First $FinalLineNumber $FinalData = $FinalData | Where-Object {$_ -match "="} } else { $FinalData = $RawContext | Where-Object {$_ -match "="} } New-Variable -Scope Global -Name $Conf -Value ($FinalData | Out-String | ConvertFrom-StringData) -Force } #endregion $RawXamlForm = @' <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="Active Directory Password reset Utility" Height="216" Width="424" WindowStartupLocation="CenterScreen" Topmost="True" ResizeMode="NoResize"> <Grid> <TextBox x:Name="UserAccount" HorizontalAlignment="Left" Height="30" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="265" FontSize="16"/> <Button x:Name="ResetPassword" Content="Reset-Password" HorizontalAlignment="Left" Margin="280,10,0,0" VerticalAlignment="Top" Width="125" Height="30"/> <RadioButton x:Name="Char15Radio" Content="15 Char" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top" IsChecked="True"/> <RadioButton x:Name="Char20Radio" Content="20 Char" HorizontalAlignment="Left" Margin="123,45,0,0" VerticalAlignment="Top"/> <Label x:Name="Message" Content="User Unlocked, Password Change at next logon" HorizontalAlignment="Left" Margin="5,105,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1.316,-0.423" Width="260" Foreground="Red"/> <TextBox x:Name="NewPassword" Text='New password show here' HorizontalAlignment="Left" Height="34" Margin="35,71,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="345" FontSize="20" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> <Label x:Name="Url" Content="http://vcloud-lab.com" HorizontalAlignment="Left" Margin="278,105,0,0" VerticalAlignment="Top" Foreground="Blue"/> <Button x:Name="SendPassword" Content="Send-Password" HorizontalAlignment="Left" Margin="280,141,0,0" VerticalAlignment="Top" Width="125" Height="24"/> <TextBox x:Name="Manager" Text="TL or Manager email id" HorizontalAlignment="Left" Height="23" Margin="10,141,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="265"/> </Grid> </Window> '@ $RawXamlForm = $RawXamlForm -replace 'x:', '' [xml]$XamlForm = $RawXamlForm $XMLReader = (New-Object System.Xml.XmlNodeReader $XamlForm) $AccountResetForm = [Windows.Markup.XamlReader]::Load($XMLReader) $XamlForm.SelectNodes("//*[@Name]") | Foreach-Object {Set-Variable -Name ($_.Name) -Value $AccountResetForm.FindName($_.Name)} $Url.Add_MouseDoubleClick({[system.Diagnostics.Process]::start('http://vcloud-lab.com')}) function Show-MessageBox { param ( [string]$Message = "Show user friendly Text Message", [string]$Title = 'Title here', [ValidateRange(0,5)] [Int]$Button = 0, [ValidateSet('None','Hand','Error','Stop','Question','Exclamation','Warning','Asterisk','Information')] [string]$Icon = 'Error' ) #Note: $Button is equl to [System.Enum]::GetNames([System.Windows.Forms.MessageBoxButtons]) #Note: $Icon is equl to [System.Enum]::GetNames([System.Windows.Forms.MessageBoxIcon]) $MessageIcon = [System.Windows.Forms.MessageBoxIcon]::$Icon [System.Windows.Forms.MessageBox]::Show($Message,$Title,$Button,$MessageIcon) } Function Confirm-AD { $AllModules = Get-Module -ListAvailable ActiveDirectory if (!$AllModules) { Show-MessageBox -Message 'Install RSAT tool or AD Management tools' | Out-Null } else { Import-Module ActiveDirectory } } Function Reset-Password { if ($Char15Radio.IsChecked) {$PasswordLength = 15} else {$PasswordLength = 20} $GeneratedPassword = New-Password -PasswordLength $PasswordLength $UserName = $UserAccount.Text.trim() if ($UserName -eq '') { $NewPassword.text = 'UserName is empty' $Manager.Text = 'TL or Manager email id' } else { try { $UserAc = Get-ADUser -Filter {Name -eq $UserName} -Properties Manager -ErrorAction Stop if ($UserAc -ne $null) { try { $UserAc | Set-ADAccountPassword -NewPassword (ConvertTo-SecureString -AsPlainText $GeneratedPassword -Force) -Reset -ErrorAction Stop $UserAc | Set-ADUser -ChangePasswordAtLogon:$true -PasswordNeverExpires:$false -ErrorAction Stop $UserAc | Unlock-ADAccount -Confirm:$false -ErrorAction Stop $NewPassword.text = $GeneratedPassword try { $ManagerEmail = Get-ADUser -Identity $UserAc.Manager -Properties Mail -ErrorAction Stop if ($ManagerEmail.Mail -ne $null) { $Script:ManagerName = $ManagerEmail.Name $Manager.Text = $ManagerEmail.Mail $ps1path = Split-Path -Parent $PSCommandPath #$ps1path = $MyInvocation.MyCommand.Definition $IniFilePath = Join-Path $ps1path -ChildPath conf.ini if (Test-Path $IniFilePath) { $EmailConfiguration = Get-IniConfiguration -File $IniFilePath -Conf Emailserver $Script:IniConfInfo = $Emailserver $SendPassword.IsEnabled = $true $Script:Body = @" <html> <body> <font face="verdana"><br>Dear Sir/Madam,<br/> <br>We found you are a manager of user $($UserAc.Name) in our database, Password for user $($UserAc.Name) has been changed and reset by HelpDesk team, new password is $($GeneratedPassword), Please ask your colleague to try after 15 mins<br /> <br>Thank you.<br/> <br>Regards<br/> <br>HelpDesk<br/> </body> </html> "@ $Script:UserInfo = $userac $SendPassword.Add_Click({ try { Send-MailMessage -From $Script:IniConfInfo['From'] -To $Manager.Text -Subject "Password Reset Notification! $($Script:UserInfo.name)" -Body $Script:Body -BodyAsHtml -SmtpServer $Script:IniConfInfo['SMTPServer'] -Port $Script:IniConfInfo['port'] -ErrorAction Stop $Manager.Text = "Email sent to Manager $($Script:ManagerName)" $SendPassword.IsEnabled = $false } catch { $Manager.Text = 'Cannot send email' } }) } } else { $Manager.Text = 'No TL or Manager found for user' } } catch { $Manager.Text = 'No TL or Manager found for user' } } catch { $NewPassword.text = "Can't set password" $Manager.Text = 'TL or Manager email id' } } else { $NewPassword.text = "User didn't found" $Manager.Text = 'TL or Manager email id' } } catch { $NewPassword.text = "Restart this PC or Can't connect AD" } } } Confirm-AD $NewPassword.IsReadOnly = $true $Manager.IsReadOnly = $true $ResetPassword.Add_Click({ $SendPassword.IsEnabled = $false Reset-Password }) $SendPassword.IsEnabled = $false [void]$AccountResetForm.ShowDialog()

Useful articles

PART 1 : INSTALL ACTIVE DIRECTORY DOMAIN CONTROLLER ON VMWARE WORKSTATION

PART 2 : CONFIGURE AND PROMOTE ACTIVE DIRECTORY DOMAIN CONTROLLER ON VMWARE WORKSTATION

PART 3 : CREATING NEW USERS IN ACTIVE DIRECTORY FOR VMWARE VSPHERE LAB

Build a simple email server for home lab using hMailServer and Thunderbird