Solved

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

Posted on 2013-11-04
3
467 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 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
A procedure for exporting installed hotfix details of remote computers using powershell
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now