-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindMalEmail.ps1
101 lines (80 loc) · 3.88 KB
/
FindMalEmail.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
#Created to find mal-emails and show option to delete them.
#Creation date : 1-14-2016
#Creator: Alix N Hoover
#Add exchange snap-in to allow the right click run
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
#Start of main menu
$title = "Find (and delete) mal-email(s)"
$message = "How to do you want to search?"
$Email = New-Object System.Management.Automation.Host.ChoiceDescription "&Email", `
"Find Email(s) by the Senders Address"
$Subject = New-Object System.Management.Automation.Host.ChoiceDescription "&Subject", `
"Find Email(s) By Subject"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($Email, $Subject)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
#Start of Switch
switch ($result)
{#open switch
#Start of the search by Sender
0 {#open case 0
Write-host "Sender of Email you wish to find:" -foregroundcolor magenta -nonewline
$Semail = read-host
Write-host "Your Email to send report to:" -foregroundcolor magenta -nonewline
$Oemail = read-host
Get-mailbox -resultsize Unlimited | Search-Mailbox -SearchQuery ("From:" +$Semail) -TargetMailbox $Oemail -TargetFolder "Powershell Report"
Write-host "Completed: look in your inbox for the folder -Powershell Report-" -foregroundcolor magenta
Write-host "Once you have checked, do you want to Delete from the users mailbox?" -foregroundcolor magenta
#Popup yes or no to delete
#Button Types
#
#Value Description
#0 Show OK button.
#1 Show OK and Cancel buttons.
#2 Show Abort, Retry, and Ignore buttons.
#3 Show Yes, No, and Cancel buttons.
#4 Show Yes and No buttons.
#5 Show Retry and Cancel buttons.
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to delete these email(s)?",0,"Delete Email(s)",4)
If ($intAnswer -eq 6)
{ # open IF to yes or no
$a.popup("Email(s) are being Delete.")
Get-mailbox -resultsize Unlimited | Search-Mailbox -SearchQuery ("From:" +$Semail) -TargetMailbox $Oemail -TargetFolder "Powershell Delete Report" -DeleteContent -Force -LogLevel Full
} # Close IF to yes or no
else { # open Else to yes or no
$a.popup("Email(s) will be kept.")
write-host "Email(s) will be kept, closing script"
} # Close Else to yes or no
}#close case 0
#Start of the Search by Subject
1 {#open case 1
Write-host "Subject of Email(s) you wish to find:" -foregroundcolor magenta -nonewline
$Semail = read-host
Write-host "Your Email to send report to:" -foregroundcolor magenta -nonewline
$Oemail = read-host
Get-mailbox -resultsize Unlimited | Search-Mailbox -SearchQuery ("Subject:" +$Semail) -TargetMailbox $Oemail -TargetFolder "Powershell Report"
Write-host "Completed: look in your inbox for the folder -Powershell Report-" -foregroundcolor magenta
Write-host "Once you have checked, do you want to Delete from the users mailbox?" -foregroundcolor magenta
#Popup yes or no to delete
#Button Types
#
#Value Description
#0 Show OK button.
#1 Show OK and Cancel buttons.
#2 Show Abort, Retry, and Ignore buttons.
#3 Show Yes, No, and Cancel buttons.
#4 Show Yes and No buttons.
#5 Show Retry and Cancel buttons.
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to delete these email(s)?",0,"Delete Email(s)",4)
If ($intAnswer -eq 6)
{ # open IF to yes or no
$a.popup("Email(s) are being Delete.")
Get-mailbox -resultsize Unlimited | Search-Mailbox -SearchQuery ("Subject:" +$Semail) -TargetMailbox $Oemail -TargetFolder "Powershell Delete Report" -DeleteContent -Force -LogLevel Full
} # Close IF to yes or no
else { # open Else to yes or no
$a.popup("Email(s) will be kept.")
write-host "Email(s) will be kept, closing script"
} # Close Else to yes or no
}#close case 1
} # Close Switch