-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-MS365AccountsCreatedSinceLast30Days.ps1
119 lines (91 loc) · 2.66 KB
/
get-MS365AccountsCreatedSinceLast30Days.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<#PSScriptInfo
.VERSION 1.2
.AUTHOR TechnologyWanderers Youtube Channel
.COMPANYNAME
.COPYRIGHT
.TAGS O365 Reprt
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES https://www.youtube.com/c/technologywanderers
#>
#requires -Version 3.0 -Modules MSOnline
#Provide O365 admin creds
#create crdential here this in only one time command # it once xml is generated.
#Get-Credential "[email protected]" | Export-Clixml .\creds.xml
#Authenticate with XML file
$cred = Import-Clixml "C:\Automation\credentials\automation.xml"
#create Session
connect-msolservice -Credential $cred
# Creating a function that generates the reports
function Get-Office365IdentityReport {
#Several reports
$a=Get-MsolUser -All | where-object {$_.whenCreated -gt (Get-Date).AddDays(-30)} | select UserPrincipalName,isLicensed,WhenCreated | ConvertTo-Html
#$b=Get-MsolUser -All | Where {$_.IsLicensed -eq $True -AND $_.BlockCredential -eq $True} | Select UserPrincipalName,isLicensed,WhenCreated,BlockCredential | ConvertTo-Html
# Creating the HTML Page
$Html = @"
<!DOCTYPE html>
<head>
<title>MS 365 License & Unlicensed users created last 30 days</title>
<style>
body {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
table, th, td {
white-space: nowrap;
border: 1px solid black;
text-align: center;
border-collapse: collapse;
padding: 4px;
}
th {
background-color: midnightblue;
color: white;
}
</style>
</head>
<body>
Dear Team,<br>
<br>
This report will help:<br>
To identify MS 365 Licensed & Unlicensed users created last <b>30 days</b><br>
To identify MS 365 Overall Licensed but SignIn Blocked Users, so license can be <b>raclaimed</b> if missed during termination.<br>
<br>
<centre>
MS 365 Licensed & Unlicensed users created last 30 days
</centre>
<br>
<centre>
<table class="Techwanderers">
<tr>
<td class="Techwanderers-1" colspan="26">$a</td>
</tr>
</table>
</centre>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Best Regards,<br>
Office 365 Automation Support<br>
URL: https://www.youtube.com/c/technologywanderers<br>
India<br>
"@
$date=(get-date).ToShortDateString()
##########################change your email address and other values here##########################
Send-Mailmessage -from "[email protected]" -To "[email protected]" -Subject "Automation: MS 365 Licensed & Unlicensed users created last 30 days - $date" -body $html -BodyAsHtml -Credential $cred -SmtpServer smtp.office365.com -Port 587 -UseSsl
}
# Running the function
Get-Office365IdentityReport
exit