Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query AD for passwords which are going to expire before certain date/hour + generate mail

Posted on 2013-11-04
3
Medium Priority
?
500 Views
Last Modified: 2013-11-06
Hi,

Please advise howto generate a list of mailadresses which contain AD-users of which their account will expire before tomorrow morning x hour.

J.
0
Comment
Question by:janhoedt
  • 2
3 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39621492
0
 

Author Comment

by:janhoedt
ID: 39621831
No, it does not. I'm looking for a Powershell command and I 'd like to split things up. First I need to see the expiry date, then generate the mailaddresses.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39622072
So you don't want the automated email.. Just need to export the password expiry date and the email address? If yes (and your domain controllers are Win 2008 R2 or later) then you can use the modified version of Get-XADUserPasswordExpirationDate function...

Ref :http://blogs.msdn.com/b/adpowershell/archive/2010/02/26/find-out-when-your-password-expires.aspx

function Get-XADUserPasswordExpirationDate() {

    Param ([Parameter(Mandatory=$true,  Position=0,  ValueFromPipeline=$true, HelpMessage="Identity of the Account")]

    [Object] $accountIdentity)

    PROCESS {

        $accountObj = Get-ADUser $accountIdentity -properties Mail, PasswordExpired, PasswordNeverExpires, PasswordLastSet

        if ($accountObj.PasswordExpired) {

	New-Object PSobject -Property @{
	User = $accountObj.Name
	EMail = $accountObj.Mail
	Status = "Password already expired!"
	}

        } else { 

            if ($accountObj.PasswordNeverExpires) {
						
	    New-Object PSobject -Property @{
	    User = $accountObj.Name
	    EMail = $accountObj.Mail
	    Status = "Password is set to never expires!"
	    }

            } else {

                $passwordSetDate = $accountObj.PasswordLastSet

                if ($passwordSetDate -eq $null) {
	
                 New-Object PSobject -Property @{
	         User = $accountObj.Name
	         EMail = $accountObj.Mail
	         Status = "Password has never been set!"
	         }
               
               } else {

                    $maxPasswordAgeTimeSpan = $null

                    $dfl = (get-addomain).DomainMode

                    if ($dfl -ge 3) { 

                        ## Greater than Windows2008 domain functional level

                        $accountFGPP = Get-ADUserResultantPasswordPolicy $accountObj

                        if ($accountFGPP -ne $null) {

                            $maxPasswordAgeTimeSpan = $accountFGPP.MaxPasswordAge

                        } else {

                            $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

                        }

                    } else {

                        $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

                    }

                    if ($maxPasswordAgeTimeSpan -eq $null -or $maxPasswordAgeTimeSpan.TotalMilliseconds -eq 0) {

		    New-Object PSobject -Property @{
		    User = $accountObj.Name
		    EMail = $accountObj.Mail
		    Status = "MaxPasswordAge is not set for the domain or is set to zero!"
		    }

                    } else {

			New-Object PSobject -Property @{
			User = $accountObj.Name
			EMail = $accountObj.Mail
			Status = $passwordSetDate + $maxPasswordAgeTimeSpan
			}
                    }

                }

            }

        }

    }

}

Open in new window

To get the accounts expires with in next day..
Get-Aduser -filter * | Get-XADUserPasswordExpirationDate | ?{$_.Status -le (Get-date).Adddays(1)}

Open in new window

You can also pipe this output to Export-CSV to export the details to csv file..
0

Featured Post

Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question