-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-enterpriseadmincount.ps1
30 lines (29 loc) · 1.35 KB
/
check-enterpriseadmincount.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
$groups = 'Enterprise Admins'
[int]$LastCount=Get-Content "e:\scripts\ian\csv\EACount.txt"
$SmtpSender = "[email protected]"
$SmtpSubject = "MFA Users weekly Report"
$SmtpServer = "graf-a-exht01.graftonplc.net"
$graftonplcEmail = "[email protected]"
foreach($Group in $Groups){
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty SamAccountName
If($LastCount -eq $Members.count)
{
$Message = "$Group contains $($members.count) members - this is the same as the previous check"
}
if($members.count -lt $LastCount)
{
$Difference = $LastCount - $members.count
$Message = "$Group contains $($members.count) members - this has decreased by $Difference since the previous check"
}
if($members.count -gt $lastcount)
{
$Difference = $Members.count - $LastCount
$Message = "$Group contains $($members.count) members - this has Increased by $Difference since the previous check"
}
}
write-host $Message -ForegroundColor Red
$OutputInt = $members.count
$OutputInt
[string]$OutputStr=$OutputInt
set-content e:\scripts\ian\csv\EACount.txt $OutputStr
Send-MailMessage -Body $Message -BodyAsHtml -From $SmtpSender -To $graftonplcEmail -Subject $SmtpSubject -SmtpServer $SmtpServer