Solved

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

Posted on 2013-11-04
3
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

624 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