Microsoft 365 Password Expiration Notification Email Solution for On-Premises AD Accounts

Published Oct 18 2021 12:00 AM 4,121 Views
Microsoft

"Hello Again World!"

Hi there! Mike Kullish, here. I'm a Microsoft Customer Engineer (CE) based just off the Gulf Coast of  Florida with a focus on AD, Hyper-V and DFS, but I try to help customers with anything on the Windows Desktop and/or Server platforms. (Also, this whole Azure thing has become a big deal, so I dabble with that as well…) I have been with Microsoft for over nine years and this is a follow-up to my first blog post written about 6 years ago which can be found here: How to Setup a Password Expiration Notification Email Solution - Microsoft Tech Community. The changes below help to eliminate the use of SMTP servers and allow you to use Microsoft Graph to send emails. This is a more modern take on the original article. I must acknowledge two of my CE colleagues that helped this update come together. First David Morillo, who assisted in wordsmithing the article, and secondly the mastermind behind the script that makes it all work, Daniel Carroll.

Have you ever had a need to configure notifications for user's password expirations but found that existing solutions didn't quite fit the bill? We all know you can use built-in solutions with Windows and Active Directory/Group Policy but this requires users to interactively log-on to a domain joined computer. What about those BYOD or mobile users or users of web apps/email? Typically, these users will have to call the helpdesk because they had no idea their domain passwords were going to expire. Statistics show that some of the most common calls to the helpdesk are password-related and implementing a process like the one covered here could really make a dent in your helpdesk call volume and costs.

The first article mentioned above enabled you to use an existing SMTP server to configure and send emails to users that had passwords which were about to expire. This solution was based on the Send-MailMessage cmdlet which is now considered obsolete. Below, we will describe the process to setup a script that uses Microsoft Graph to send email using your M365 subscription.

 

MichaelKullish_0-1632940746924.png

 

I thought it would make a helpful blog post to cover some of the details and considerations when implementing a solution like this. As mentioned, Daniel Carroll deserves credit for the script that follows.

 

DISCLAIMER:

  • The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
  • CEs don't normally provide code beyond sample or "proof of concept" code
  • The code we discuss here is an additional layer beyond code from a CE; it is code from a passion project of Dan’s that was trimmed to fit the need of this article.
  • As with ANY code, you should always test/validate its behavior in an isolated lab
  •  Did I mention you should test/validate the code? I have also validated that it works on Windows Server 2019 and Windows Server 2022.
  • If/when you're ready to deploy it to production, you should employ a solid change control process and a controlled release. This code can possibly generate emails to thousands of users .

You can download the script from the following link .  I will also post a full copy of the code within the article, but updates will be made more frequently on GitHub. ( Script to Automate Email Reminders when Users Passwords due to Expire using O365 Shared Mailbox · Gi... )

Click on the blue box and save the file to a workstation or member server. Obviously, a DC would work but likely isn't the best choice. The workstation or member server needs the RSAT tools for Active Directory installed. If you already have an "admin server" system where you have existing scripts, tools, Scheduled Tasks, etc., that would be a logical place for this. I would also suggest creating a folder such as C:\temp on the tools machine in order to ensure you can follow along easily with the instructions below.

 

 

#################################################################################################################
#
# Original Robert Pearman v1.4 Passowrd Change Notification
#    - Adapted to support O365 SendAS Shared Mailbox
# Script to Automate Email Reminders when Users Passwords due to Expire using O365 Shared Mailbox.
#
# Requires: 
#        Windows PowerShell Module for Active Directory
#        Azure AD Application registration with MS Graph Application Mail.Send permission
#
#
##################################################################################################################
# Please Configure the following variables....
$expireindays = 21
$logging = "Enabled" # Set to Disabled to Disable Logging
$logFile = "" # ie. c:\mylog.csv
$testing = "Enabled" # Set to Disabled to Email Users
$testRecipient = ''
$clientId = '' # App registration ID used to send on behalf of shared mailbox
$clientSecret = (Import-Clixml -Path $PSScriptRoot\SendEmailSecret.ps1.credential).GetNetworkCredential().Password #Client Secret credential file
$tenantName = '' #TenantName
$SendEmailAccount = '' #SharedMailbox name
$resource = 'https://graph.microsoft.com' #Graph Endpoint https://graph.microsoft.com or https://graph.microsoft.us or https://dod-graph.microsoft.us
#
###################################################################################################################

$ReqTokenBody = @{
    Grant_Type    = "client_credentials"
    Scope         = "$($resource)/.default"
    client_Id     = $clientID
    Client_Secret = $clientSecret
} 
Try {
    $params = @{
        Uri         = "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token"
        Method      = "POST"
        ErrorAction = "Stop"
    }
    $TokenResponse = Invoke-RestMethod @params -Body $ReqTokenBody

    if ($TokenResponse) {
        # Check Logging Settings
        if (($logging) -eq "Enabled")
        {
            # Test Log File Path
            $logfilePath = (Test-Path $logFile)
            if (($logFilePath) -ne "True")
            {
                # Create CSV File and Headers
                New-Item $logfile -ItemType File
                Add-Content $logfile "Date,Name,EmailAddress,DaystoExpire,ExpiresOn,Notified"
            }
        } # End Logging Check

        # System Settings
        $textEncoding = [System.Text.Encoding]::UTF8
        $date = Get-Date -format ddMMyyyy
        # End System Settings

        # Get Users From AD who are Enabled, Passwords Expire and are Not Currently Expired
        Import-Module ActiveDirectory
        $users = get-aduser -filter * -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress |where {$_.Enabled -eq "True"} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false }
        $DefaultmaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

        # Process Each User for Password Expiry
        foreach ($user in $users)
        {
            $Name = $user.Name
            $emailaddress = $user.emailaddress
            $passwordSetDate = $user.PasswordLastSet
            $PasswordPol = (Get-AduserResultantPasswordPolicy $user)
            $sent = "" # Reset Sent Flag
            # Check for Fine Grained Password
            if (($PasswordPol) -ne $null)
            {
                $maxPasswordAge = ($PasswordPol).MaxPasswordAge
            }
            else
            {
                # No FGP set to Domain Default
                $maxPasswordAge = $DefaultmaxPasswordAge
            }


            $expireson = $passwordsetdate + $maxPasswordAge
            $today = (get-date)
            $daystoexpire = (New-TimeSpan -Start $today -End $Expireson).Days

            # Set Greeting based on Number of Days to Expiry.

            # Check Number of Days to Expiry
            $messageDays = $daystoexpire

            if (($messageDays) -gt "1")
            {
                $messageDays = "in " + "$daystoexpire" + " days."
            }
            else
            {
                $messageDays = "today."
            }
                # If Testing Is Enabled - Email Administrator
            if (($testing) -eq "Enabled")
            {
                $emailaddress = $testRecipient
            } # End Testing

            # If a user has no email address listed
            if (($emailaddress) -eq $null)
            {
                $emailaddress = $testRecipient
            }# End No Valid Email

            # Email Subject Set Here
            $subject="Your password will expire $messageDays"

            # Email Body Set Here, Note You can use HTML.
            $body = @"
            {
              "Message": {
                "Subject": "$($subject)",
                "importance":"High",
                "Body": {
                  "ContentType": "HTML",
                  "Content": "<p>Dear $($name),</p>
            <p> Your Password will expire $($messageDays)<br>
            To change your password on a PC press CTRL ALT Delete and choose Change Password <br>
            <p>Thanks, <br>
            </P>"
                },
                "ToRecipients": [
                  {
                    "EmailAddress": {
                      "Address": "$($emailaddress)"
                    }
                  }
                ]
              },
              "SaveToSentItems": "false",
              "isDraft": "false"
            }
"@

            # Send Email Message
            if (($daystoexpire -ge "0") -and ($daystoexpire -lt $expireindays))
            {
                $sent = "Yes"
                # If Logging is Enabled Log Details
                if (($logging) -eq "Enabled")
                {
                    Add-Content $logfile "$date,$Name,$emailaddress,$daystoExpire,$expireson,$sent"
                }
                # Send Email Message
                $apiUrl = "$resource/v1.0/users/$SendEmailAccount/sendMail"
                Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Body $Body -Method Post -ContentType 'application/json'

            } # End Send Message
            else # Log Non Expiring Password
            {
                $sent = "No"
                # If Logging is Enabled Log Details
                if (($logging) -eq "Enabled")
                {
                    Add-Content $logfile "$date,$Name,$emailaddress,$daystoExpire,$expireson,$sent"
                }
            }
        }

        } # End User Processing

} catch {
    [System.ApplicationException]::new("Failed to aquire token")
}

 

 

Once you have downloaded or created your own copy of the script:

  • Create a shared mailbox in M365 to be used if you haven’t already done so.
    • In the example for this article, we will use smtp1.contoso.com
  • Log into Azure AD and register a new App by selecting “App registrations”
    • Select New registration and fill in the fields as appropriate

2A.png

    • Click Register
  • Copy Application ID from the Overview section of the newly created SendMail app:

3A.png

 

  • Place Application (client) ID GUID on line 19 of script you downloaded
  • From the SendMail application blade in Azure AD Click on “Certificates & secrets”
    • Click on New client secret
    • Choose options like below or as appropriate for your organization

5B.png

  • Click Add when finished
    • When you create the secret, this is the only time you can get it (You should copy this to the clipboard and to a file if necessary): 3AA7Q~YSlo1235Pxvjq6U7vE6uanqXYZTOqC5
      • Don’t share this information. You will have to recreate the secret if you ever want it again and don’t save a copy.
  • Open an elevated PowerShell prompt
  • Run the following from an elevated PowerShell (This will add the client secret from your app to the script using DPAPI and pins the credentials to the tools machine based on the user running the script…am I stressing this point yet?):
    • $cred = ’3AA7Q~YSlo1235Pxvjq6U7vE6uanqXYZTOqC5'
      [System.Management.Automation.PSCredential]::new( "SendEmailCred", (ConvertTo-SecureString -String $cred -AsPlainText -Force) ) | Export-Clixml -Path C:\temp\test.ps1.credential
  • Fill in $tenantName and $testRecipient in script
  • Set Permissions on the app:
    • Goto the app you just created in Azure AD
    • Choose API Permissions from the blade on the left
    • Choose “Application permissions” and the Mail.Send permission while in the blade as depicted below:

7A.png

    • Choose Add permissions when ready
    • Then click on Grant admin consent for your domain when prompted

7B.png

    • You should then see permissions similar to the following:

7C.png

  • Place the .PS1 file in a directory on your admin server. (For this example, I will use C:\temp)
  • Edit the following portions of the script as applicable using Notepad or PowerShell ISE if you haven’t already done so:
    • $expireindays = 21 
      • This is the number of days prior to password expiration that you want to notify users. The actual number of days remaining before expiration will be displayed in the email notification.
    • $logging = "Enabled" # Set to Disabled to Disable Logging
      • Logging is recommended to ensure that you can trace any errors that might occur
    • $logFile = "C:\temp\pwdexplog.csv"
      • This field should be changed to a desired location on the local system or network share as desired.
    • $testing = "Enabled"
      • Set to Disabled to email users (configuring this to Enabled, runs a check against all accounts and sends emails ONLY the account specified in the $testRecipient field below.)
        • Configuring this to disabled actually sends emails to the users that will have their passwords expire in the configured amount of time.
        • Understand this - you risk sending out a mass-email to 10s, 100s or 10,000s of users.
        • This is automation – with great power, comes great responsibility
    • $testRecipient = "user@domain.com"
      • This will provide a test recipient email address to ensure the script is working properly
    • $clientId = ""
      • This will be the app registration ID used to send on behalf of as shared mailbox in use (example: 71267c5f-b88d-aaaa-a3e4-370d101234ac)
    • $tenantName = ""
      • This is the name of your tenant (Example: Contoso.onmicrosoft.com)
    • $SendEmailAccount = "someone@company.com"
    • $clientSecret  = (Import-Clixml -Path C:\Scripts\sendemailsecret.ps1.credential).GetNetworkCredential().password #Client Secret from AAD
      • This secret can be found by running the following on the tools machine. Note: It is important that the account running the following scripts is also the account used to manually run the PowerShell script manually or to run any scheduled tasks which may use the script from GitHub. (Reference Article: Export-Clixml (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs)

 

 

$cred = '3BW7Q~YSlo2oS5Pxvjq6U7vE6uanqQnGTOqC5' 
[System.Management.Automation.PSCredential]::new( "SendEmailCred", (ConvertTo-SecureString -String $cred -AsPlainText -Force) ) | Export-Clixml -Path C:\temp\SendEmailSecret.ps1.credential

#The credential specified in $cred above should be gathered when creating the App Registration

 

 

  • Save the script once you are done editing it.
  • Now you can test the script by running it in a lab.
    • You may need to modify the execution policy for PowerShell scripts on your admin server machine.
  • You should get an email that looks something like this:
  • From: someone@company.com [mailto:someone@company.com]
    Sent: Thursday, September 28, 2021 12:52 PM
    To: Someone@company.com
    Dear chptest,

    To change your password on a PC press CTRL-ALT-Delete and choose Change Password

    Thanks,

 

  • It is important to ensure that you change the section of the script under $body .  The message should be modified to ensure that users don't accidentally delete the email because they suspect it is spam or a phishing email. Good inter-team collaboration and communication about this "password expiration notification process" cannot be emphasized enough.
    • Work with your helpdesk and security teams to ensure everyone signs off on this effort and approves the specific text and additional information for the email, including how to manage a 'reply' to that email address
  • When it all is working as desired/expected, you can disable testing:
    • $testing = "Disabled"

Now, at some pre-determined time, you or one of your staff can execute the script to generate the 'password expiry notification email' to the affected users.

For those who don't want to manually run the script, it's a simple process to create a Scheduled Task to run the script automatically. I would strongly suggest investigating the use of a Group Managed Service account rather than a traditional user account that runs a script or service, but that is a topic for another article.

There are numerous other ways to address this need; I have talked to many people who have developed their own processes, scripts and/or code for this. This particular process was pretty easy to implement, and I was able to work with my customers and my own lab environment to get the whole thing working in a short amount of time.

One last point of consideration would be to start moving away from passwords altogether. Think about multi-factor authentication (MFA), or passwordless solutions for an added bonus. One article that will help get you started can be found here: Azure Active Directory passwordless sign-in | Microsoft Docs.

Thanks again to David Morillo, Daniel Carroll, and everyone that responded to the original post to inspire this update.

 

See you all next time!

Mike "CANNONBALL!" Kullish

Michael Kullish -or- aka.ms/michaelkullish

 

 

 

 

4 Comments
%3CLINGO-SUB%20id%3D%22lingo-sub-2796353%22%20slang%3D%22en-US%22%3EMicrosoft%20365%20Password%20Expiration%20Notification%20Email%20Solution%20for%20On-Premises%20AD%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2796353%22%20slang%3D%22en-US%22%3E%3CP%3E%22Hello%20Again%20World!%22%3C%2FP%3E%0A%3CP%3EHi%20there!%20Mike%20Kullish%2C%20here.%26nbsp%3BI'm%20a%20Microsoft%20Customer%20Engineer%20(CE)%20based%20just%20off%20the%20Gulf%20Coast%20of%20%26nbsp%3BFlorida%20with%20a%20focus%20on%26nbsp%3BAD%2C%20Hyper-V%20and%20DFS%2C%20but%20I%26nbsp%3Btry%20to%20help%20customers%20with%20anything%26nbsp%3Bon%20the%26nbsp%3BWindows%20Desktop%20and%2For%20Server%20platforms.%20(Also%2C%20this%20whole%20Azure%20thing%20has%20become%20a%20big%20deal%2C%20so%20I%20dabble%20with%20that%20as%20well%E2%80%A6)%26nbsp%3BI%20have%20been%20with%20Microsoft%20for%20over%20nine%20years%26nbsp%3Band%20this%20is%20a%20follow-up%20to%20my%20first%20blog%20post%20written%20about%206%20years%20ago%20which%20can%20be%20found%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fcore-infrastructure-and-security%2Fhow-to-setup-a-password-expiration-notification-email-solution%2Fbc-p%2F2767566%22%20target%3D%22_blank%22%3EHow%20to%20Setup%20a%20Password%20Expiration%20Notification%20Email%20Solution%20-%20Microsoft%20Tech%20Community%3C%2FA%3E.%20The%20changes%20below%20help%20to%20eliminate%20the%20use%20of%20SMTP%20servers%20and%20allow%20you%20to%20use%20Microsoft%20Graph%20to%20send%20emails.%20This%20is%20a%20more%20modern%20take%20on%20the%20original%20article.%20I%20must%20acknowledge%20two%20of%20my%20CE%20colleagues%20that%20helped%20this%20update%20come%20together.%20First%20David%20Morillo%2C%20who%20assisted%20in%20wordsmithing%20the%20article%2C%20and%20secondly%20the%20mastermind%20behind%20the%20script%20that%20makes%20it%20all%20work%2C%20Daniel%20Carroll.%3C%2FP%3E%0A%3CP%3EHave%20you%20ever%20had%20a%20need%20to%20configure%20notifications%20for%20user's%20password%20expirations%20but%20found%20that%20existing%20solutions%20didn't%20quite%20fit%20the%20bill%3F%20We%20all%20know%20you%20can%20use%20built-in%20solutions%20with%20Windows%20and%20Active%20Directory%2FGroup%20Policy%20but%20this%20requires%20users%20to%20interactively%20log-on%20to%20a%20domain%20joined%20computer.%20What%20about%20those%26nbsp%3BBYOD%20or%20mobile%20users%20or%26nbsp%3Busers%20of%20web%20apps%2Femail%3F%20Typically%2C%20these%20users%20will%20have%20to%20call%20the%20helpdesk%20because%20they%20had%20no%20idea%20their%20domain%20passwords%20were%20going%20to%20expire.%20Statistics%20show%20that%20some%20of%20the%20most%20common%20calls%20to%20the%20helpdesk%20are%20password-related%20and%20implementing%20a%26nbsp%3Bprocess%20like%20the%20one%20covered%20here%20could%20really%20make%20a%20dent%20in%20your%20helpdesk%20call%20volume%26nbsp%3Band%20costs.%3C%2FP%3E%0A%3CP%3EThe%20first%20article%20mentioned%20above%20enabled%20you%20to%20use%20an%20existing%20SMTP%20server%20to%20configure%20and%20send%20emails%20to%20users%20that%20had%20passwords%20which%20were%20about%20to%20expire.%20This%20solution%20was%20based%20on%20the%20Send-MailMessage%20cmdlet%20which%20is%20now%20considered%20obsolete.%20Below%2C%20we%20will%20describe%20the%20process%20to%20setup%20a%20script%20that%20uses%20Microsoft%20Graph%20to%20send%20email%20using%20your%20M365%20subscription.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22MichaelKullish_0-1632940746924.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313699i64043D386E57F33F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22MichaelKullish_0-1632940746924.png%22%20alt%3D%22MichaelKullish_0-1632940746924.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20thought%20it%20would%20make%20a%20helpful%20blog%20post%20to%20cover%20some%20of%20the%20details%20and%20considerations%20when%20implementing%20a%20solution%20like%20this.%20As%20mentioned%2C%20Daniel%20Carroll%20deserves%20credit%20for%20the%20script%20that%20follows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDISCLAIMER%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20sample%20scripts%20are%20not%20supported%20under%20any%20Microsoft%20standard%20support%20program%20or%20service.%20The%20sample%20scripts%20are%20provided%20AS%20IS%20without%20warranty%20of%20any%20kind.%20Microsoft%20further%20disclaims%20all%20implied%20warranties%20including%2C%20without%20limitation%2C%20any%20implied%20warranties%20of%20merchantability%20or%20of%20fitness%20for%20a%20particular%20purpose.%20The%20entire%20risk%20arising%20out%20of%20the%20use%20or%20performance%20of%20the%20sample%20scripts%20and%20documentation%20remains%20with%20you.%20In%20no%20event%20shall%20Microsoft%2C%20its%20authors%2C%20or%20anyone%20else%20involved%20in%20the%20creation%2C%20production%2C%20or%20delivery%20of%20the%20scripts%20be%20liable%20for%20any%20damages%20whatsoever%20(including%2C%20without%20limitation%2C%20damages%20for%20loss%20of%20business%20profits%2C%20business%20interruption%2C%20loss%20of%20business%20information%2C%20or%20other%20pecuniary%20loss)%20arising%20out%20of%20the%20use%20of%20or%20inability%20to%20use%20the%20sample%20scripts%20or%20documentation%2C%20even%20if%20Microsoft%20has%20been%20advised%20of%20the%20possibility%20of%20such%20damages.%3C%2FLI%3E%0A%3CLI%3ECEs%20don't%20normally%20provide%20code%20beyond%20sample%20or%20%22proof%20of%20concept%22%20code%3C%2FLI%3E%0A%3CLI%3EThe%20code%20we%20discuss%20here%20is%20an%20additional%20layer%20beyond%26nbsp%3Bcode%20from%20a%20CE%3B%20it%20is%20code%20from%20a%20passion%20project%20of%20Dan%E2%80%99s%20that%20was%20trimmed%20to%20fit%20the%20need%20of%20this%20article.%3C%2FLI%3E%0A%3CLI%3EAs%20with%20ANY%20code%2C%20you%20should%20always%20test%2Fvalidate%20its%20behavior%20in%20an%20isolated%20lab%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BDid%20I%20mention%20you%20should%20test%2Fvalidate%20the%20code%3F%20I%20have%20also%20validated%20that%20it%20works%20on%20Windows%20Server%202019%20and%20Windows%20Server%202022.%3C%2FLI%3E%0A%3CLI%3EIf%2Fwhen%20you're%20ready%20to%20deploy%20it%20to%20production%2C%20you%20should%20employ%20a%20solid%20change%20control%20process%20and%20a%20controlled%20release.%26nbsp%3B%3CSTRONG%3EThis%20code%20can%20possibly%20generate%20emails%20to%20thousands%20of%20users%26nbsp%3B%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20can%20download%20the%20script%20from%20the%20following%26nbsp%3Blink%26nbsp%3B.%20%26nbsp%3BI%20will%20also%20post%20a%20full%20copy%20of%20the%20code%20within%20the%20article%2C%20but%20updates%20will%20be%20made%20more%20frequently%20on%20GitHub.%20(%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgist.github.com%2Fdacarroll%2F12f53cb90052b29452a03571587519aa%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EScript%20to%20Automate%20Email%20Reminders%20when%20Users%20Passwords%20due%20to%20Expire%20using%20O365%20Shared%20Mailbox%20%C2%B7%20GitHub%3C%2FA%3E%26nbsp%3B)%3C%2FP%3E%0A%3CP%3EClick%20on%20the%20blue%20box%20and%20save%20the%20file%26nbsp%3Bto%20a%20workstation%20or%20member%20server.%20Obviously%2C%20a%20DC%20would%20work%20but%20likely%20isn't%20the%20best%20choice.%20The%20workstation%20or%20member%20server%20needs%20the%20RSAT%20tools%20for%20Active%20Directory%20installed.%20If%20you%20already%20have%20an%20%22admin%20server%22%26nbsp%3Bsystem%20where%20you%20have%20existing%20scripts%2C%20tools%2C%20Scheduled%20Tasks%2C%20etc.%2C%20that%20would%20be%20a%20logical%20place%20for%20this.%20I%20would%20also%20suggest%20creating%20a%20folder%20such%20as%20C%3A%5Ctemp%20on%20the%20tools%20machine%20in%20order%20to%20ensure%20you%20can%20follow%20along%20easily%20with%20the%20instructions%20below.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%23%0A%23%20Original%20Robert%20Pearman%20v1.4%20Passowrd%20Change%20Notification%0A%23%20%20%20%20-%20Adapted%20to%20support%20O365%20SendAS%20Shared%20Mailbox%0A%23%20Script%20to%20Automate%20Email%20Reminders%20when%20Users%20Passwords%20due%20to%20Expire%20using%20O365%20Shared%20Mailbox.%0A%23%0A%23%20Requires%3A%20%0A%23%20%20%20%20%20%20%20%20Windows%20PowerShell%20Module%20for%20Active%20Directory%0A%23%20%20%20%20%20%20%20%20Azure%20AD%20Application%20registration%20with%20MS%20Graph%20Application%20Mail.Send%20permission%0A%23%0A%23%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%23%20Please%20Configure%20the%20following%20variables....%0A%24expireindays%20%3D%2021%0A%24logging%20%3D%20%22Enabled%22%20%23%20Set%20to%20Disabled%20to%20Disable%20Logging%0A%24logFile%20%3D%20%22%22%20%23%20ie.%20c%3A%5Cmylog.csv%0A%24testing%20%3D%20%22Enabled%22%20%23%20Set%20to%20Disabled%20to%20Email%20Users%0A%24testRecipient%20%3D%20''%0A%24clientId%20%3D%20''%20%23%20App%20registration%20ID%20used%20to%20send%20on%20behalf%20of%20shared%20mailbox%0A%24clientSecret%20%3D%20(Import-Clixml%20-Path%20%24PSScriptRoot%5CSendEmailSecret.ps1.credential).GetNetworkCredential().Password%20%23Client%20Secret%20credential%20file%0A%24tenantName%20%3D%20''%20%23TenantName%0A%24SendEmailAccount%20%3D%20''%20%23SharedMailbox%20name%0A%24resource%20%3D%20'https%3A%2F%2Fgraph.microsoft.com'%20%23Graph%20Endpoint%20https%3A%2F%2Fgraph.microsoft.com%20or%20https%3A%2F%2Fgraph.microsoft.us%20or%20https%3A%2F%2Fdod-graph.microsoft.us%0A%23%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%0A%24ReqTokenBody%20%3D%20%40%7B%0A%20%20%20%20Grant_Type%20%20%20%20%3D%20%22client_credentials%22%0A%20%20%20%20Scope%20%20%20%20%20%20%20%20%20%3D%20%22%24(%24resource)%2F.default%22%0A%20%20%20%20client_Id%20%20%20%20%20%3D%20%24clientID%0A%20%20%20%20Client_Secret%20%3D%20%24clientSecret%0A%7D%20%0ATry%20%7B%0A%20%20%20%20%24params%20%3D%20%40%7B%0A%20%20%20%20%20%20%20%20Uri%20%20%20%20%20%20%20%20%20%3D%20%22https%3A%2F%2Flogin.microsoftonline.com%2F%24TenantName%2Foauth2%2Fv2.0%2Ftoken%22%0A%20%20%20%20%20%20%20%20Method%20%20%20%20%20%20%3D%20%22POST%22%0A%20%20%20%20%20%20%20%20ErrorAction%20%3D%20%22Stop%22%0A%20%20%20%20%7D%0A%20%20%20%20%24TokenResponse%20%3D%20Invoke-RestMethod%20%40params%20-Body%20%24ReqTokenBody%0A%0A%20%20%20%20if%20(%24TokenResponse)%20%7B%0A%20%20%20%20%20%20%20%20%23%20Check%20Logging%20Settings%0A%20%20%20%20%20%20%20%20if%20((%24logging)%20-eq%20%22Enabled%22)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Test%20Log%20File%20Path%0A%20%20%20%20%20%20%20%20%20%20%20%20%24logfilePath%20%3D%20(Test-Path%20%24logFile)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24logFilePath)%20-ne%20%22True%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Create%20CSV%20File%20and%20Headers%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20New-Item%20%24logfile%20-ItemType%20File%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Add-Content%20%24logfile%20%22Date%2CName%2CEmailAddress%2CDaystoExpire%2CExpiresOn%2CNotified%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%20%23%20End%20Logging%20Check%0A%0A%20%20%20%20%20%20%20%20%23%20System%20Settings%0A%20%20%20%20%20%20%20%20%24textEncoding%20%3D%20%5BSystem.Text.Encoding%5D%3A%3AUTF8%0A%20%20%20%20%20%20%20%20%24date%20%3D%20Get-Date%20-format%20ddMMyyyy%0A%20%20%20%20%20%20%20%20%23%20End%20System%20Settings%0A%0A%20%20%20%20%20%20%20%20%23%20Get%20Users%20From%20AD%20who%20are%20Enabled%2C%20Passwords%20Expire%20and%20are%20Not%20Currently%20Expired%0A%20%20%20%20%20%20%20%20Import-Module%20ActiveDirectory%0A%20%20%20%20%20%20%20%20%24users%20%3D%20get-aduser%20-filter%20*%20-properties%20Name%2C%20PasswordNeverExpires%2C%20PasswordExpired%2C%20PasswordLastSet%2C%20EmailAddress%20%7Cwhere%20%7B%24_.Enabled%20-eq%20%22True%22%7D%20%7C%20where%20%7B%20%24_.PasswordNeverExpires%20-eq%20%24false%20%7D%20%7C%20where%20%7B%20%24_.passwordexpired%20-eq%20%24false%20%7D%0A%20%20%20%20%20%20%20%20%24DefaultmaxPasswordAge%20%3D%20(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge%0A%0A%20%20%20%20%20%20%20%20%23%20Process%20Each%20User%20for%20Password%20Expiry%0A%20%20%20%20%20%20%20%20foreach%20(%24user%20in%20%24users)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%24Name%20%3D%20%24user.Name%0A%20%20%20%20%20%20%20%20%20%20%20%20%24emailaddress%20%3D%20%24user.emailaddress%0A%20%20%20%20%20%20%20%20%20%20%20%20%24passwordSetDate%20%3D%20%24user.PasswordLastSet%0A%20%20%20%20%20%20%20%20%20%20%20%20%24PasswordPol%20%3D%20(Get-AduserResultantPasswordPolicy%20%24user)%0A%20%20%20%20%20%20%20%20%20%20%20%20%24sent%20%3D%20%22%22%20%23%20Reset%20Sent%20Flag%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Check%20for%20Fine%20Grained%20Password%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24PasswordPol)%20-ne%20%24null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24maxPasswordAge%20%3D%20(%24PasswordPol).MaxPasswordAge%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20No%20FGP%20set%20to%20Domain%20Default%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24maxPasswordAge%20%3D%20%24DefaultmaxPasswordAge%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24expireson%20%3D%20%24passwordsetdate%20%2B%20%24maxPasswordAge%0A%20%20%20%20%20%20%20%20%20%20%20%20%24today%20%3D%20(get-date)%0A%20%20%20%20%20%20%20%20%20%20%20%20%24daystoexpire%20%3D%20(New-TimeSpan%20-Start%20%24today%20-End%20%24Expireson).Days%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Set%20Greeting%20based%20on%20Number%20of%20Days%20to%20Expiry.%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Check%20Number%20of%20Days%20to%20Expiry%0A%20%20%20%20%20%20%20%20%20%20%20%20%24messageDays%20%3D%20%24daystoexpire%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24messageDays)%20-gt%20%221%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24messageDays%20%3D%20%22in%20%22%20%2B%20%22%24daystoexpire%22%20%2B%20%22%20days.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24messageDays%20%3D%20%22today.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20If%20Testing%20Is%20Enabled%20-%20Email%20Administrator%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24testing)%20-eq%20%22Enabled%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24emailaddress%20%3D%20%24testRecipient%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%23%20End%20Testing%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20If%20a%20user%20has%20no%20email%20address%20listed%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24emailaddress)%20-eq%20%24null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24emailaddress%20%3D%20%24testRecipient%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%23%20End%20No%20Valid%20Email%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Email%20Subject%20Set%20Here%0A%20%20%20%20%20%20%20%20%20%20%20%20%24subject%3D%22Your%20password%20will%20expire%20%24messageDays%22%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Email%20Body%20Set%20Here%2C%20Note%20You%20can%20use%20HTML.%0A%20%20%20%20%20%20%20%20%20%20%20%20%24body%20%3D%20%40%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Message%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Subject%22%3A%20%22%24(%24subject)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22importance%22%3A%22High%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Body%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ContentType%22%3A%20%22HTML%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Content%22%3A%20%22%3CP%3EDear%20%24(%24name)%2C%3C%2FP%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CP%3E%20Your%20Password%20will%20expire%20%24(%24messageDays)%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20To%20change%20your%20password%20on%20a%20PC%20press%20CTRL%20ALT%20Delete%20and%20choose%20Change%20Password%20%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FP%3E%3CP%3EThanks%2C%20%3CBR%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FP%3E%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22ToRecipients%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22EmailAddress%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Address%22%3A%20%22%24(%24emailaddress)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22SaveToSentItems%22%3A%20%22false%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isDraft%22%3A%20%22false%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%22%40%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Send%20Email%20Message%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24daystoexpire%20-ge%20%220%22)%20-and%20(%24daystoexpire%20-lt%20%24expireindays))%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24sent%20%3D%20%22Yes%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20If%20Logging%20is%20Enabled%20Log%20Details%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24logging)%20-eq%20%22Enabled%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Add-Content%20%24logfile%20%22%24date%2C%24Name%2C%24emailaddress%2C%24daystoExpire%2C%24expireson%2C%24sent%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20Send%20Email%20Message%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24apiUrl%20%3D%20%22%24resource%2Fv1.0%2Fusers%2F%24SendEmailAccount%2FsendMail%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Invoke-RestMethod%20-Headers%20%40%7BAuthorization%20%3D%20%22Bearer%20%24(%24Tokenresponse.access_token)%22%7D%20-Uri%20%24apiUrl%20-Body%20%24Body%20-Method%20Post%20-ContentType%20'application%2Fjson'%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%23%20End%20Send%20Message%0A%20%20%20%20%20%20%20%20%20%20%20%20else%20%23%20Log%20Non%20Expiring%20Password%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24sent%20%3D%20%22No%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20If%20Logging%20is%20Enabled%20Log%20Details%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20((%24logging)%20-eq%20%22Enabled%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Add-Content%20%24logfile%20%22%24date%2C%24Name%2C%24emailaddress%2C%24daystoExpire%2C%24expireson%2C%24sent%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%7D%20%23%20End%20User%20Processing%0A%0A%7D%20catch%20%7B%0A%20%20%20%20%5BSystem.ApplicationException%5D%3A%3Anew(%22Failed%20to%20aquire%20token%22)%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20you%20have%20downloaded%20or%20created%20your%20own%20copy%20of%20the%20script%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreate%20a%20shared%20mailbox%20in%20M365%20to%20be%20used%20if%20you%20haven%E2%80%99t%20already%20done%20so.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3COL%3E%0A%3CUL%3E%0A%3CLI%3EIn%20the%20example%20for%20this%20article%2C%20we%20will%20use%20smtp1.contoso.com%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FOL%3E%0A%3CUL%3E%0A%3CLI%3ELog%20into%20Azure%20AD%20and%20register%20a%20new%20App%20by%20selecting%20%E2%80%9CApp%20registrations%E2%80%9D%3CUL%3E%0A%3CLI%3ESelect%20New%20registration%20and%20fill%20in%20the%20fields%20as%20appropriate%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%222A.png%22%20style%3D%22width%3A%20605px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313770i5A0A2738A2AF4E3F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%222A.png%22%20alt%3D%222A.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CUL%3E%0A%3CLI%3EClick%20Register%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3ECopy%20Application%20ID%20from%20the%20Overview%20section%20of%20the%20newly%20created%20SendMail%20app%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%223A.png%22%20style%3D%22width%3A%20594px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313774i249FCDA06EBBCD23%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%223A.png%22%20alt%3D%223A.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EPlace%20Application%20(client)%20ID%20GUID%20on%20line%2019%20of%20script%20you%20downloaded%3C%2FLI%3E%0A%3CLI%3EFrom%20the%20SendMail%20application%20blade%20in%20Azure%20AD%20Click%20on%20%E2%80%9CCertificates%20%26amp%3B%20secrets%E2%80%9D%3CUL%3E%0A%3CLI%3EClick%20on%20New%20client%20secret%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CUL%3E%0A%3CLI%3EChoose%20options%20like%20below%20or%20as%20appropriate%20for%20your%20organization%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%225B.png%22%20style%3D%22width%3A%20707px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313777i40B26925E037D3C3%2Fimage-dimensions%2F707x212%3Fv%3Dv2%22%20width%3D%22707%22%20height%3D%22212%22%20role%3D%22button%22%20title%3D%225B.png%22%20alt%3D%225B.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EClick%20Add%20when%20finished%3CUL%3E%0A%3CLI%3EWhen%20you%20create%20the%20secret%2C%20this%20is%20the%20only%20time%20you%20can%20get%20it%20(You%20should%20copy%20this%20to%20the%20clipboard%20and%20to%20a%20file%20if%20necessary)%3A%203AA7Q~YSlo1235Pxvjq6U7vE6uanqXYZTOqC5%3CUL%3E%0A%3CLI%3EDon%E2%80%99t%20share%20this%20information.%20You%20will%20have%20to%20recreate%20the%20secret%20if%20you%20ever%20want%20it%20again%20and%20don%E2%80%99t%20save%20a%20copy.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EOpen%20an%20elevated%20PowerShell%20prompt%3C%2FLI%3E%0A%3CLI%3ERun%20the%20following%20from%20an%20elevated%20PowerShell%20(This%20will%20add%20the%20client%20secret%20from%20your%20app%20to%20the%20script%20using%20DPAPI%20and%20pins%20the%20credentials%20to%20the%20tools%20machine%20based%20on%20the%20user%20running%20the%20script%E2%80%A6am%20I%20stressing%20this%20point%20yet%3F)%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CUL%3E%0A%3CLI%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24cred%20%3D%20%E2%80%993AA7Q~YSlo1235Pxvjq6U7vE6uanqXYZTOqC5'%0A%5BSystem.Management.Automation.PSCredential%5D%3A%3Anew(%20%22SendEmailCred%22%2C%20(ConvertTo-SecureString%20-String%20%24cred%20-AsPlainText%20-Force)%20)%20%7C%20Export-Clixml%20-Path%20C%3A%5Ctemp%5Ctest.ps1.credential%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EFill%20in%20%24tenantName%20and%20%24testRecipient%20in%20script%3C%2FLI%3E%0A%3CLI%3ESet%20Permissions%20on%20the%20app%3A%3CUL%3E%0A%3CLI%3EGoto%20the%20app%20you%20just%20created%20in%20Azure%20AD%3C%2FLI%3E%0A%3CLI%3EChoose%20API%20Permissions%20from%20the%20blade%20on%20the%20left%3C%2FLI%3E%0A%3CLI%3EChoose%20%E2%80%9CApplication%20permissions%E2%80%9D%20and%20the%20Mail.Send%20permission%20while%20in%20the%20blade%20as%20depicted%20below%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%227A.png%22%20style%3D%22width%3A%20894px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313736iF96FFF62A9861C77%2Fimage-dimensions%2F894x917%3Fv%3Dv2%22%20width%3D%22894%22%20height%3D%22917%22%20role%3D%22button%22%20title%3D%227A.png%22%20alt%3D%227A.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CUL%3E%0A%3CLI%3EChoose%20Add%20permissions%20when%20ready%3C%2FLI%3E%0A%3CLI%3EThen%20click%20on%20Grant%20admin%20consent%20for%20your%20domain%20when%20prompted%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%227B.png%22%20style%3D%22width%3A%20604px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313779i47324AA538A5B1B1%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%227B.png%22%20alt%3D%227B.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CUL%3E%0A%3CLI%3EYou%20should%20then%20see%20permissions%20similar%20to%20the%20following%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%227C.png%22%20style%3D%22width%3A%20706px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313933i2CAFA9484EB9AA66%2Fimage-dimensions%2F706x471%3Fv%3Dv2%22%20width%3D%22706%22%20height%3D%22471%22%20role%3D%22button%22%20title%3D%227C.png%22%20alt%3D%227C.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EPlace%20the%20.PS1%20file%20in%20a%20directory%20on%20your%20admin%20server.%20(For%20this%20example%2C%20I%20will%20use%20C%3A%5Ctemp)%3C%2FLI%3E%0A%3CLI%3EEdit%20the%20following%20portions%20of%20the%20script%20as%20applicable%26nbsp%3Busing%20Notepad%20or%20PowerShell%20ISE%20if%20you%20haven%E2%80%99t%20already%20done%20so%3A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%24expireindays%20%3D%2021%3C%2FSTRONG%3E%26nbsp%3B%3CUL%3E%0A%3CLI%3EThis%20is%20the%20number%20of%20days%20prior%20to%20password%20expiration%26nbsp%3Bthat%20you%20want%20to%20notify%20users.%20The%20actual%20number%20of%20days%20remaining%26nbsp%3Bbefore%20expiration%20will%20be%20displayed%20in%20the%20email%20notification.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24logging%20%3D%20%22Enabled%22%20%23%20Set%20to%20Disabled%20to%20Disable%20Logging%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3ELogging%20is%20recommended%20to%20ensure%20that%20you%20can%20trace%20any%20errors%20that%20might%20occur%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24logFile%20%3D%20%22C%3A%5Ctemp%5Cpwdexplog.csv%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EThis%20field%20should%20be%20changed%20to%20a%20desired%20location%20on%20the%20local%20system%20or%20network%20share%20as%20desired.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24testing%20%3D%20%22Enabled%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3ESet%20to%20Disabled%20to%20email%20users%20(configuring%20this%26nbsp%3Bto%20Enabled%2C%20runs%20a%26nbsp%3Bcheck%26nbsp%3Bagainst%20all%20accounts%20and%26nbsp%3Bsends%20emails%20ONLY%20the%26nbsp%3Baccount%20specified%20in%20the%20%24testRecipient%20field%20below.)%3CUL%3E%0A%3CLI%3E%3CEM%3EConfiguring%20this%20to%26nbsp%3B%3CSTRONG%3Edisabled%26nbsp%3Bactually%20sends%20emails%20to%20the%20users%26nbsp%3B%3C%2FSTRONG%3Ethat%20will%20have%20their%20passwords%20expire%20in%20the%20configured%20amount%20of%20time.%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%3CEM%3EUnderstand%20this%26nbsp%3B%3C%2FEM%3E%3C%2FSTRONG%3E%3CEM%3E-%20you%20risk%20sending%20out%20a%20mass-email%20to%2010s%2C%20100s%20or%2010%2C000s%20of%20users.%3C%2FEM%3E%3C%2FLI%3E%0A%3CLI%3E%3CEM%3EThis%20is%20automation%20%E2%80%93%20with%20great%20power%2C%20comes%20great%20responsibility%3C%2FEM%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24testRecipient%20%3D%20%22user%40domain.com%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EThis%20will%20provide%20a%20test%20recipient%20email%20address%20to%20ensure%20the%20script%20is%20working%20properly%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24clientId%20%3D%20%22%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EThis%20will%20be%20the%20app%20registration%20ID%20used%20to%20send%20on%20behalf%20of%20as%20shared%20mailbox%20in%20use%20(example%3A%2071267c5f-b88d-aaaa-a3e4-370d101234ac)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24tenantName%20%3D%20%22%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EThis%20is%20the%20name%20of%20your%20tenant%20(Example%3A%20Contoso.onmicrosoft.com)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24SendEmailAccount%20%3D%20%22someone%40company.com%22%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3ESpecifies%20the%20shared%20mailbox%20name.%20(Example%3A%20%3CA%20href%3D%22mailto%3AM365mailbox%40contoso.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%3CEM%3EM365mailbox%40contoso.com%3C%2FEM%3E%3C%2FA%3E%3CEM%3E)%3C%2FEM%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3E%24clientSecret%20%26nbsp%3B%3D%20%3C%2FSTRONG%3E(Import-Clixml%20-Path%20C%3A%5CScripts%5Csendemailsecret.ps1.credential).GetNetworkCredential().password%20%23Client%20Secret%20from%20AAD%3CUL%3E%0A%3CLI%3E%3CEM%3EThis%20secret%20can%20be%20found%20by%20running%20the%20following%20on%20the%20tools%20machine.%20%3CSTRONG%3ENote%3A%20It%20is%20important%20that%20the%20account%20running%20the%20following%20scripts%20is%20also%20the%20account%20used%20to%20manually%20run%20the%20PowerShell%20script%20manually%20or%20to%20run%20any%20scheduled%20tasks%20which%20may%20use%20the%20script%20from%20GitHub.%20(Reference%20Article%3A%20%3C%2FSTRONG%3E%3C%2FEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmicrosoft.powershell.utility%2Fexport-clixml%3Fview%3Dpowershell-7.1%23example-3--encrypt-an-exported-credential-object-on-windows%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExport-Clixml%20(Microsoft.PowerShell.Utility)%20-%20PowerShell%20%7C%20Microsoft%20Docs%3C%2FA%3E%3CSTRONG%3E%3CEM%3E)%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24cred%20%3D%20'3BW7Q~YSlo2oS5Pxvjq6U7vE6uanqQnGTOqC5'%20%0A%5BSystem.Management.Automation.PSCredential%5D%3A%3Anew(%20%22SendEmailCred%22%2C%20(ConvertTo-SecureString%20-String%20%24cred%20-AsPlainText%20-Force)%20)%20%7C%20Export-Clixml%20-Path%20C%3A%5Ctemp%5CSendEmailSecret.ps1.credential%0A%0A%23The%20credential%20specified%20in%20%24cred%20above%20should%20be%20gathered%20when%20creating%20the%20App%20Registration%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESave%20the%20script%20once%20you%20are%20done%20editing%20it.%3C%2FLI%3E%0A%3CLI%3ENow%20you%20can%20test%20the%20script%20by%20running%20it%26nbsp%3Bin%20a%20lab.%3CUL%3E%0A%3CLI%3EYou%20may%20need%20to%20modify%20the%20execution%20policy%20for%20PowerShell%20scripts%20on%20your%20admin%20server%20machine.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EYou%20should%20get%20an%20email%20that%20looks%20something%20like%20this%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%20style%3D%22list-style-type%3A%20none%3B%22%3E%3CP%3E%3CSTRONG%3E%3CEM%3EFrom%3A%20someone%40company.com%20%5Bmailto%3Asomeone%40company.com%5D%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3ESent%3A%20Thursday%2C%20September%2028%2C%202021%2012%3A52%20PM%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3ETo%3A%20Someone%40company.com%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3EDear%20chptest%2C%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3ETo%20change%20your%20password%20on%20a%20PC%20press%20CTRL-ALT-Delete%20and%20choose%20Change%20Password%20%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3EThanks%2C%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIt%20is%20important%20to%20ensure%20that%20you%20change%20the%20section%20of%20the%20script%20under%26nbsp%3B%24body%26nbsp%3B.%26nbsp%3B%20The%20message%20should%20be%20modified%20to%20ensure%20that%20users%20don't%20accidentally%20delete%20the%20email%20because%20they%20suspect%20it%20is%20spam%20or%20a%20phishing%20email.%26nbsp%3BGood%20inter-team%20collaboration%20and%20communication%20about%20this%20%22password%20expiration%20notification%20process%22%20cannot%20be%20emphasized%20enough.%3CUL%3E%0A%3CLI%3EWork%20with%20your%20helpdesk%20and%20security%20teams%20to%20ensure%20everyone%20signs%20off%20on%20this%20effort%20and%20approves%20the%20specific%20text%20and%20additional%20information%20for%20the%20email%2C%20including%26nbsp%3Bhow%20to%20manage%20a%20'reply'%20to%20that%20email%20address%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EWhen%20it%26nbsp%3Ball%20is%20working%26nbsp%3Bas%20desired%2Fexpected%2C%20you%20can%20disable%26nbsp%3Btesting%3A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%24testing%20%3D%20%22Disabled%22%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ENow%2C%20at%20some%20pre-determined%20time%2C%20you%20or%20one%20of%20your%20staff%20can%20execute%20the%20script%20to%20generate%20the%20'password%20expiry%20notification%20email'%20to%20the%20affected%20users.%3C%2FP%3E%0A%3CP%3EFor%20those%20who%20don't%20want%20to%20manually%20run%20the%20script%2C%20it's%20a%20simple%20process%20to%20create%20a%20Scheduled%20Task%20to%20run%20the%20script%20automatically.%20I%20would%20strongly%20suggest%20investigating%20the%20use%20of%20a%20Group%20Managed%20Service%20account%20rather%20than%20a%20traditional%20user%20account%20that%20runs%20a%20script%20or%20service%2C%20but%20that%20is%20a%20topic%20for%20another%20article.%3C%2FP%3E%0A%3CP%3EThere%20are%20numerous%20other%20ways%20to%20address%20this%20need%3B%26nbsp%3BI%20have%20talked%20to%20many%26nbsp%3Bpeople%20who%20have%20developed%20their%20own%20processes%2C%20scripts%20and%2For%20code%20for%20this.%20This%20particular%20process%26nbsp%3Bwas%26nbsp%3Bpretty%20easy%20to%20implement%2C%20and%20I%20was%20able%20to%20work%20with%20my%20customers%20and%20my%20own%20lab%20environment%20to%20get%20the%20whole%20thing%20working%20in%20a%20short%20amount%20of%20time.%3C%2FP%3E%0A%3CP%3EOne%20last%20point%20of%20consideration%20would%20be%20to%20start%20moving%20away%20from%20passwords%20altogether.%20Think%20about%20multi-factor%20authentication%20(MFA)%2C%20or%20passwordless%20solutions%20for%20an%20added%20bonus.%20One%20article%20that%20will%20help%20get%20you%20started%20can%20be%20found%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fauthentication%2Fconcept-authentication-passwordless%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Active%20Directory%20passwordless%20sign-in%20%7C%20Microsoft%20Docs%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EThanks%20again%20to%20David%20Morillo%2C%20Daniel%20Carroll%2C%20and%20everyone%20that%20responded%20to%20the%20original%20post%20to%20inspire%20this%20update.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20you%20all%20next%20time!%3C%2FP%3E%0A%3CP%3EMike%20%22CANNONBALL!%22%20Kullish%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.linkedin.com%2Fin%2Fmichael-kullish%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EMichael%20Kullish%3C%2FA%3E%26nbsp%3B-or-%20aka.ms%2Fmichaelkullish%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2796353%22%20slang%3D%22en-US%22%3E%3CP%3EForget%20about%20SMTP%2C%20this%20article%20will%20help%20you%20configure%20Email%20notifications%20for%20Active%20Directory%20users%20that%20have%20expiring%20passwords%20by%20utilizing%20Microsoft%20Graph%2C%20and%20M365.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22M365Logo.jpg%22%20style%3D%22width%3A%20253px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F313710i308E7901609BDBD2%2Fimage-dimensions%2F253x136%3Fv%3Dv2%22%20width%3D%22253%22%20height%3D%22136%22%20role%3D%22button%22%20title%3D%22M365Logo.jpg%22%20alt%3D%22M365Logo.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2796353%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMichaelKullish%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2921398%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20365%20Password%20Expiration%20Notification%20Email%20Solution%20for%20On-Premises%20AD%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2921398%22%20slang%3D%22en-US%22%3E%3CP%3EI%20had%20a%20question%20about%20the%20Redirect%20URL%2C%20how%20do%20i%20obtain%20that%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2938385%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20365%20Password%20Expiration%20Notification%20Email%20Solution%20for%20On-Premises%20AD%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2938385%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20when%20using%20a%20group%20managed%20service%20account%20(gMSA)%20to%20run%20scheduled%20tasks%20you%20have%20to%20run%20this%20also%20under%20this%20gMSA%20service%20account%3F%3A%3CBR%20%2F%3E%3CEM%3E'.%20Note%26nbsp%3B%24clientSecret%3A%20It%20is%20important%20that%20the%20account%20running%20the%20following%20scripts%20is%20also%20the%20account%20used%20to%20manually%20run%20the%20PowerShell%20script%20manually%20or%20to%20run%20any%20scheduled%20tasks%20which%20may%20use%20the%20script%20from%20GitHub.'%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2932200%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20365%20Password%20Expiration%20Notification%20Email%20Solution%20for%20On-Premises%20AD%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2932200%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F241879%22%20target%3D%22_blank%22%3E%40Michael%20Kullish%3C%2FA%3E%26nbsp%3B-%26nbsp%3B%20I've%20gone%20through%20the%20instructions%20several%20times%20and%20checked%20variable%20values%20and%20everything%20seems%20correct%20but%20my%20results%20are%20%22Failed%20to%20aquire%20(sic)%20token%22%20Like%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1205564%22%20target%3D%22_blank%22%3E%40kk212%3C%2FA%3E%26nbsp%3BI%20was%20unsure%20on%20what%20to%20put%20in%20the%20Redirect%20URL%20field.%20If%20this%20is%20indeed%20the%20issue%20could%20you%20please%20elaborate%20on%20that%20step%20of%20the%20instructions%3F%20Looking%20forward%20to%20getting%20this%20working%2C%20thanks%20for%20your%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*Solved*%3C%2FP%3E%3CP%3ESet%20my%20redirect%20URI%20to%20%3CA%20href%3D%22http%3A%2F%2Flocalhost%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Flocalhost%3C%2FA%3E%26nbsp%3Band%20used%20the%20Directory%20(tenant%20ID)%20from%20the%20AzureAD%20app%20Overview%20blade%20for%20the%20%24Tenantname%20variable%20within%20the%20script.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Sep 30 2021 05:46 AM
Updated by: