Created
July 31, 2024 09:59
-
-
Save jamiechalmerzlp/67f447ce8f86320e38fbb383ed995daf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if ExchangeOnlineManagement module is installed | |
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) { | |
Write-Host "ExchangeOnlineManagement module is not installed. Installing it..." | |
# Install the ExchangeOnlineManagement module from the PowerShell Gallery | |
Install-Module -Name ExchangeOnlineManagement -Force -Scope CurrentUser | |
if ($?) { | |
Write-Host "ExchangeOnlineManagement module has been successfully installed." -ForegroundColor Green | |
} else { | |
Write-Host "Failed to install the ExchangeOnlineManagement module." -ForegroundColor Red | |
} | |
} else { | |
Write-Host "ExchangeOnlineManagement module is already installed." -ForegroundColor DarkGreen | |
} | |
# Prompt for the user's email address | |
$OperatorUPN = Read-Host "Please enter your email address" | |
# Connect to Exchange Online | |
Connect-ExchangeOnline -UserPrincipalName $OperatorUPN | |
# Connect to IPSSession | |
Connect-IPPSSession -UserPrincipalName $OperatorUPN | |
# Get search details | |
$SearchName = Read-Host "Enter an appropriate search name" | |
$MailDate = Read-Host "Enter the date the email was received (USA Format MM/DD/YYYY)" | |
$SubjectOrStartOf = Read-Host "Now enter the start of the subject or the full subject line" | |
# Create the Content Search - Results can be found here: https://compliance.microsoft.com/contentsearchv2? | |
$Search = New-ComplianceSearch -Name "$SearchName" -ExchangeLocation All -ContentMatchQuery "(Received:$MailDate) AND (Subject:`"$SubjectOrStartOf`")" | |
Start-ComplianceSearch -Identity $Search.Identity | |
# Open Web Result | |
Write-Host "BEFORE CHOOSING YOUR OPTION PLEASE ALLOW AT LEAST 5 MINUTES FOR THE SEARCH TO RUN. IF IT IS GOING TO BE A BIG SEARCH ALLOW LONGER." | |
$OpenResult = Read-Host "Would you like to see the search result? (Accepted Inputs: Y/YES, N/NO)" | |
if ($OpenResult -eq "y" -or $OpenResult -eq "Y" -or $OpenResult -eq "YES") { | |
Write-Host "Opening Microsoft Compliance Content Search" -ForegroundColor Green | |
Start-Process "https://compliance.microsoft.com/contentsearchv2?" | |
} elseif ($OpenResult -eq "n" -or $OpenResult -eq "N" -or $OpenResult -eq "NO") { | |
Write-Host "### SKIPPING URL ###" -ForegroundColor Magenta | |
} else { | |
Write-Host "Invalid Input. Please enter 'y' or 'n' (non-case sensitive). Script will re-run after 5 seconds." -ForegroundColor Red | |
Start-Sleep -Seconds 5 | |
# Restart the script | |
& "$PSCommandPath" | |
} | |
# Create a Compliance Search Action to purge | |
New-ComplianceSearchAction -SearchName "$SearchName" -Purge -PurgeType SoftDelete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment