?
Solved

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

Posted on 2013-11-04
3
Medium Priority
?
494 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 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

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

718 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