Send Password to user through email on new Active Directory(AD) account Creation

You can handle this in an AfterCreate or AfterModify (operation Enable for rehires) in PowerShell.

Add-Type -AssemblyName System.Web
$pass = ConvertTo-SecureString $([system.web.security.membership]::GeneratePassword(16, 2)) -AsPlainText -Force
Set-ADAccountPassword -Identity $nativeIdentity -NewPassword $pass -Confirm:$false
Set-ADUser $nativeIdentity -ChangePasswordAtLogon $true
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
$Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

$body = "$Password with other text"

$splat = @{
    SMTPServer = "smtp.server.com"
    Port       = 25
    Credential = $creds
    From       = $from
    To         = $to
    Subject    = ""
    Body       = $body
    BodyAsHtml = $true
}

Send-MailMessage @splat
2 Likes