-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreatedThisWeek.ps1
86 lines (78 loc) · 2.47 KB
/
CreatedThisWeek.ps1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#########################################
# Author: Corey Deli #
# #
# Date: March 23, 2017 #
# #
# Purpose: Send admin email for all new #
# and groups created within last week. #
# #
# Version: 1.1 #
#########################################
# Import active directory in order ot pull list of "new"
Import-Module ActiveDirectory
# Define the date, $week defines 7 days prior. $Today defines the current day/time.
$week = (Get-Date).AddDays(-7)
$today = (Get-Date).ToString()
# HTML to make the design pretty and not cluttered
$a = $a + "<style>
BODYBODY{
background-color:Lavender ;
}
TABLE{
border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
}`
TH{
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: black;
background-color:thistle
}
TD{
border-width: 1px;
padding: 5px;border-style: solid;
border-color: black;
background-color:PaleGoldenrod;
}
</style><!--mce:0-->"
# Settings for email
$smtp = "mail.contoso.com"
$port = "587"
$to = "[email protected]"
$from = "[email protected]"
$subject = "New Users and New Groups created since $week"
# Run report on users created in the last week
$Users = Get-ADUser -Filter * -Properties * |
Where-Object { $_.whenCreated -ge $week } |
Sort-Object |
Select-Object
Name, `
EmployeeID, `
Title, `
Department, `
Mail, `
physicalDeliveryOfficeName, `
StreetAddress, `
City, `
State, `
PostalCode, `
TelephoneNumber, `
Mobile, `
whenCreated |
ConvertTo-Html -Head $a -Body "<H2>Users that have been created during the week of $week.</H2>"
# Run report on all groups created in the last week
$group = Get-ADGroup -Filter * -Properties * |
Where-Object { $_.whenCreated -ge $week } |
Sort-Object |
Select-Object Name,Mail,Description,whenCreated |
ConvertTo-Html -Head $a -Body "<H2>Groups that have been created during the week of $week.</H2>"
$body = "Creation period from $week to $today ."
$body += "`n"
$body += $Users
$body += "`n"
$body += $group
$body += "`n"
Send-MailMessage -SmtpServer $smtp -Port $port -To $to -From $from -Subject $subject -Body $body -BodyAsHtml