Public/Invoke-ResetPassword.ps1

function Invoke-ResetPassword {
    <#
    .SYNOPSIS
        Generates a random password and resets the target AD user account with the new password and informs chat.
    .PARAMETER Username
        Target Active Directory user account to reset password for (sAMaccountName is best)
    .EXAMPLE
        !reset youngsamkim
    #>

    [PoshBot.BotCommand(
        CommandName = 'reset',
        Aliases = ('resetpassword')
    )]
    [cmdletbinding()]
    param(
        [parameter(Mandatory)]
        [string]$username
    )
    Import-Module ActiveDirectory

    # Find user in global catalog.
    try {
        $GCADUser = Get-ADUser -Identity $username -server sundc1:3268 -properties *
    }
    Catch {
        Write-Output "User could not be found. `n $_.Exception.ItemName `n $_.Exception.Message"
    }
    # Set variables and random password.
    $childdomain = ($GCADUser.DistinguishedName -split '(DC=)' | Select-Object -index 2).replace(',', '')
    $dc = (Get-ADDomainController -Discover -DomainName $childdomain).Name

    switch ($childdomain) {
        "stc" { $password = "Suntaiyang1!" }
        "hairzone" { $password = "Hairzone1!" }
        "bes" { $password = "Beautyessence1!" }
        "gb" { $password = "Globalbeauty1!" }
        "itsawig" { $password = "Itsawig1!" }
        "SOL" { $password = "Mamatress1!" }
    }

    $SPassword = ConvertTo-SecureString $password -AsPlainText -Force

    # Sanity logic? no more than one user
    try {
        Set-ADAccountPassword -Identity $GCADUser.DistinguishedName -NewPassword $SPassword -Reset -Server $dc
        $stringx = "Password for $username has been successfully reset. `n New Password: $password"
        New-PoshBotTextResponse -Text ($stringx | Out-String) -AsCode
    }
    catch {
        Write-Output "$($_.Exception.Message)"
        Write-Output "$($_.error.message)"
    }
}