Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

786 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