-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexchangeMenu.ps1
More file actions
120 lines (104 loc) · 4.57 KB
/
exchangeMenu.ps1
File metadata and controls
120 lines (104 loc) · 4.57 KB
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
119
120
function Format-Color([hashtable] $Colors = @{}, [switch] $SimpleMatch) {
$lines = ($input | Out-String) -replace "`r", "" -split "`n"
foreach($line in $lines) {
$color = ''
foreach($pattern in $Colors.Keys){
if(!$SimpleMatch -and $line -match $pattern) { $color = $Colors[$pattern] }
elseif ($SimpleMatch -and $line -like $pattern) { $color = $Colors[$pattern] }
}
if($color) {
Write-Host -ForegroundColor $color $line
} else {
Write-Host $line
}
}
}
function senderSearch {
$Global:senderAddress = Read-Host "Sender address"
$backlog = Read-Host "Checking only the last 48 hours. Do you want to go back further? [y/n]"
if ($backlog -eq 'n'){
Get-MessageTrace -SenderAddress $senderAddress | Format-Table Received, RecipientAddress, Status, SenderAddress, Subject, FromIP | Format-Color @{'Delivered' = 'Green'; 'FilteredAsSpam' = 'Red'}
}
elseif ($backlog -eq 'y'){
Write-Host "Searching the past 7 days." -ForegroundColor Red
Get-MessageTrace -SenderAddress $senderAddress -StartDate ((Get-Date).AddDays(-7).ToString('MM/dd/yyyy')) -EndDate (Get-Date -Uformat "%m/%d/%Y") | Format-Table Received, RecipientAddress, Status, SenderAddress, Subject, FromIP | Format-Color @{'Delivered' = 'Green'; 'FilteredAsSpam' = 'Red'}
}
}
function ipSearch {
$ipaddresss = Read-Host "IP address"
$backlog = Read-Host "Checking only the last 48 hours. Do you want to go back further? [y/n]"
if ($backlog -eq 'n'){
Get-MessageTrace -FromIP $ipaddress | Format-Table Received, RecipientAddress, Status, SenderAddress, Subject, FromIP | Format-Color @{'Delivered' = 'Green'; 'FilteredAsSpam' = 'Red'}
}
elseif ($backlog -eq 'y'){
Write-Host "Searching the past 7 days." -ForegroundColor Red
Get-MessageTrace -FromIP $senderAddress -StartDate ((Get-Date).AddDays(-7).ToString('MM/dd/yyyy')) -EndDate (Get-Date -Uformat "%m/%d/%Y") | Format-Table Received, RecipientAddress, Status, SenderAddress, Subject, FromIP | Format-Color @{'Delivered' = 'Green'; 'FilteredAsSpam' = 'Red'}
}
}
function emailPull {
$targetMailbox = Read-Host "Enter name of user [Firstname Lastname]"
$newSenderCheck = Read-Host "Keep the same sender of '$senderAddress'? [y/n]"
if ($newSenderCheck -eq 'y'){
Search-Mailbox -Identity "$targetMailbox" -SearchQuery '(from:$senderAddress)' -DeleteContent
Write-Host "Message from $sendAddress has been pulled from $targetMailbox" -ForegroundColor Red
}
elseif ($newSenderCheck -eq 'n'){
$newSender = Read-Host "Sender address"
Search-Mailbox -Identity "$targetMailbox" -SearchQuery '(from:$newSender)' -DeleteContent
Write-Host "Message from $newSender has been pulled from $targetMailbox" -ForegroundColor Red
}
$continue = Read-Host "Do you have more messages to pull? [y/n]"
if ($continue -eq 'y'){
emailPull
}
elseif ($continue -eq 'n'){
Return
}
}
function blockSender {
$blockSenderCheck = Read-Host "Keep the same sender of '$senderAddress'? [y/n]"
if ($blockSenderCheck -eq 'y'){
Set-HostedContentFilterPolicy -Identity "ULX-Spam-Policy" -BlockedSenders @{Add="$senderAddress"}
Write-Host "$senderAddress has been blocked" -ForegroundColor Red
}
elseif ($blockSenderCheck -eq 'n'){
$newBlockSender = Read-Host "Sender address to block"
Set-HostedContentFilterPolicy -Identity "ULX-Spam-Policy" -BlockedSenders @{Add="$newBlockSender"}
Write-Host "$newBlockSender has been blocked" -ForegroundColor Red
}
}
function checkRules {
$userMailbox = Read-Host "Enter user to check in form of email address"
Get-InboxRule -Mailbox $userMailbox | Select Name, Description, ForwardTo, ForwardAsAttachmentTo, RedirectTo | FL
}
function Main {
Write-Host "----------------"
Write-Host "Select a module:"
Write-Host "----------------"
Write-Host "1: Sender address search"
Write-Host "2: Sender IP address search"
Write-Host "3: Delete messages from inboxes"
Write-Host "4: Block sender address"
Write-Host "5: Check applied mailbox rules for user"
Write-Host "q: Quit"
$Global:selection = Read-Host "Selection"
if ($selection -eq '1'){
senderSearch
}
elseif ($selection -eq '2'){
ipSearch
}
elseif ($selection -eq '3'){
emailPull
}
elseif ($selection -eq '4'){
blockSender
}
elseif ($selection -eq '5'){
checkRules
}
}
do {
Main
}
until ($selection -eq 'q')