<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>check password expiration active directory powershell Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/check-password-expiration-active-directory-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/check-password-expiration-active-directory-powershell/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Sun, 16 Aug 2020 22:59:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Script: How To Check Password Expirations In Your Domain</title>
		<link>https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/</link>
					<comments>https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Wed, 25 Apr 2018 19:17:32 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[active directory password expiration policy]]></category>
		<category><![CDATA[active directory password expires attribute]]></category>
		<category><![CDATA[check if password expired active directory]]></category>
		<category><![CDATA[check password expiration active directory powershell]]></category>
		<category><![CDATA[how to check password expiration date windows]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=241</guid>

					<description><![CDATA[<p>UPDATE: March 1, 2020 Please use the updated script: https://thesysadminchannel.com/get-password-expiration-date-using-powershell-active-directory/ Chances are if you manage users in your organization, you&#8217;re going to need to Check Password Expirations In Active Directory to see who&#8217;s account is in need of a password change. &#8230; <a href="https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/">Script: How To Check Password Expirations In Your Domain</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>UPDATE: March 1, 2020<br />
Please use the updated script: <a href="https://thesysadminchannel.com/get-password-expiration-date-using-powershell-active-directory/" rel="noopener noreferrer" target="_blank">https://thesysadminchannel.com/get-password-expiration-date-using-powershell-active-directory/</a></p>
<p>Chances are if you manage users in your organization, you&#8217;re going to need to <strong>Check Password Expirations In Active Directory</strong> to see who&#8217;s account is in need of a password change.  This can be especially useful if you would like to notify those users several days in advance so they&#8217;re not calling the help desk on the day of.</p>
<p>We want to automate as much of this as possible and luckily, we have Powershell to do all the heavy lifting.</p>
<h1>Powershell Script to Check Password Expirations in Active Directory</h1>
<pre class="brush: powershell; title: ; notranslate">
&lt;#
#requires -Module ActiveDirectory


.SYNOPSIS
    Checks to see if the account is X days within password expiration.
    For updated help and examples refer to -Online version.
 
.DESCRIPTION
    In this example if the $emailDate is set to -80 and $expiredDate is set to -90 it will show all users whos passwords are within 10 days of expiration.
    For updated help and examples refer to -Online version.
 
.NOTES
    Name: Get-PasswordExpiredUsers.ps1
    Version: 1.0
    Author: The Sysadmin Channel
    Date of last revision: 3/18/2017
 
.LINK
    https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory -

#&gt;

Import-Module ActiveDirectory

#Set the number of days within expiration.  This will start to send the email x number of days before it is expired.
$DaysWithinExpiration = 10

#Set the days where the password is already expired and needs to change. -- Do Not Modify --
$MaxPwdAge   = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days
$expiredDate = (Get-Date).addDays(-$MaxPwdAge)

#Set the number of days until you would like to begin notifing the users. -- Do Not Modify --
$emailDate = (Get-Date).addDays(-($MaxPwdAge - $DaysWithinExpiration))

#Filters for all users who's password is within $date of expiration.
$ExpiredUsers = Get-ADUser -Filter {(PasswordLastSet -lt $emailDate) -and (PasswordLastSet -gt $expiredDate) -and (PasswordNeverExpires -eq $false) -and (Enabled -eq $true)} -Properties PasswordNeverExpires, PasswordLastSet, Mail | select samaccountname, PasswordLastSet, @{name = &quot;DaysUntilExpired&quot;; Expression = {$_.PasswordLastSet - $ExpiredDate | select -ExpandProperty Days}}, @{name = &quot;EmailAddress&quot;; Expression = {$_.mail}} | Sort-Object PasswordLastSet

$ExpiredUsers

</pre>
<p>Copy and Paste the contents of this file and save it as Get-PasswordExpiredUsers.ps1. Make sure you run the script as an administrator.  When you run the file it should look something like this.</p>
<div id="attachment_264" style="width: 1007px" class="wp-caption aligncenter"><a href="https://thesysadminchannel.com/wp-content/uploads/2018/04/Powershell-Check-Account-Expirations-1.png" target="_blank" rel="noopener noreferrer"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-264" class="wp-image-264 size-full" src="https://thesysadminchannel.com/wp-content/uploads/2018/04/Powershell-Check-Account-Expirations-1.png" alt="Powershell Check Account Expirations" width="997" height="490" srcset="https://thesysadminchannel.com/wp-content/uploads/2018/04/Powershell-Check-Account-Expirations-1.png 997w, https://thesysadminchannel.com/wp-content/uploads/2018/04/Powershell-Check-Account-Expirations-1-768x377.png 768w" sizes="(max-width: 997px) 100vw, 997px" /></a><p id="caption-attachment-264" class="wp-caption-text">This will filter all users and only show the samaccountname, PasswordLastSet, DaysUntilExpired and the EmailAddress</p></div>
<p>Great!! We have the script, but what good does that do us if we don&#8217;t notify them.  After all, that was the point to begin with right?  Of course it was.  We want to automate the milk out of this so we can basically set it and forget.</p>
<h1>Send Email to Notify Users of Password Expiration</h1>
<p>Now we just have to append this part to the rest of the script so we can notify our users automatically.  Here is the rest of the script.</p>
<pre class="brush: powershell; title: ; notranslate">

Start-Sleep 5

Foreach ($User in $ExpiredUsers) {
	# Creating .NET Objects
	$msg = new-object Net.Mail.MailMessage

	# Setting up the email parameters.
	$msg.From = &quot;admin@&quot; + ($env:userdnsdomain).ToLower()
	$msg.To.Add($User.EmailAddress)
	$msg.Subject = &quot;Your Password Will Expire in &quot; + $User.DaysUntilExpired + &quot; days&quot;
	$msg.Body = &quot;Hello,`n`nThis email is to notify you that your password will expire in &quot; + $User.DaysUntilExpired + &quot; days.`n`nPlease consider changing it to avoid any service interruptions.`n`nThank you,`nThe I.T. Department.&quot;


	# Send an email with an alert
	$smtpServer = &quot;mailhost&quot;
	$smtp = new-object Net.Mail.SmtpClient($smtpServer)
	$smtp.Send($msg)
	
	Start-Sleep 2
	Remove-Variable msg
	Remove-Variable smtp
	Remove-Variable smtpServer
}

</pre>
<p>The post <a href="https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/">Script: How To Check Password Expirations In Your Domain</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/powershell-script-check-password-expirations-in-active-directory/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">241</post-id>	</item>
	</channel>
</rss>
