-
Notifications
You must be signed in to change notification settings - Fork 97
/
CompareEmailPol.ps1
76 lines (55 loc) · 2.06 KB
/
CompareEmailPol.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
############################################################################
# Author: Vikas Sukhija http://msexchange.me
# Date: 12/08/2015
# Update:
# Reviewed:
# Description: Compare Email Policy Exchange
#############################################################################
# Add Exchange Shell...
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null)
{ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010}
# Add quest shell
If ((Get-PSSnapin | where {$_.Name -match "Quest.ActiveRoles.ADManagement"}) -eq $null)
{
Add-PSSnapin Quest.ActiveRoles.ADManagement
}
#######format Date################
$date = get-date -format d
$date = $date.ToString().Replace(“/”, “-”)
$output = ".\" + "EmlcomparisonReport_" + $date + "_.csv"
$Collection = @()
$domain = "domain"
$regex = "^[0-9]*$"
#######################
$allmbx = Get-Mailbox -resultsize unlimited | where{$_.CustomAttribute12 -match $regex}
$allmbx | foreach-object {
$firstN = $null
$lastN = $null
$qd = get-qaduser $_.samaccountname
$firstN = $qd.FirstName
$lastN = $qd.LastName
$firstN = $firstN.trim()
$firstN = $firstN -replace " ",""
$lastN = $lastN.trim()
$lastN = $lastN -replace " ",""
$Emlpol=$firstN + "." + $lastN + "@" + $domain + "." + "com" ### email policy
#Write-host "Formed email policy address $Emlpol" -foregroundcolor Green
$email = $_.PrimarySmtpAddress
$mbx = ""| select FirstName, Lastname,SamaccountName,Email,Formedaddress
#########compare email policy now
if($email -eq $Emlpol){
write-host "email addreses $email is as per email policy $Emlpol" -foregroundcolor Green
}
else{
write-host "email addreses is $email not as per email policy $Emlpol" -foregroundcolor magenta
$mbx.FirstName = $firstN
$mbx.LastName = $lastN
$mbx.SamaccountName = $_.samaccountname
$mbx.Email = $email
$mbx.Formedaddress = $Emlpol
$collection +=$mbx
}
}
#export the collection to csv , change the path accordingly
$Collection | export-csv $output -notypeinformation
###############################################################