-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter06.txt
34 lines (25 loc) · 1.15 KB
/
Chapter06.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
##########
Active Directory: Sending an E-Mail to Users, if their Password will expire soon
##########
#Import Active Directory Module
Import-Module ActiveDirectory
#Day of Span, to limit the Result
$SpanDays="20"
#Settings
$Displayname=@()
$Mail=@()
$Days=@()
$Sam=@()
$DN=@()
#Get all Users which are enabled and Password will expire
$Users=Get-ADUser -filter {(Enabled -eq $True) -and (PasswordNeverExpires -eq $False)} -Properties DisplayName, msDS-UserPasswordExpiryTimeComputed, Mail, samaccountname, distinguishedName | Where-Object {$_.DisplayName -ne $null} | Select Mail, samaccountname,distinguishedName, Display-Name,@{Name="ExpiryDate";Expression={([datetime]::fromfiletime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime}}
#Go through each User and check if password will expire int hte next XX Days, see Span configuaration
foreach ($Entry in $Users) {
$Span=NEW-TIMESPAN -Start (Get-Date) -End (Get-date($Entry.ExpiryDate))
if ($Span -le $SpanDays -and $Span -gt 0) {
$Displayname+=$entry.DisplayName
$Mail+=$Entry.Mail
$Days+=$span.Days
$SAM+=$Entry.samaccountname
$DN+=$Entry.distinguishedName
}