Examples
Create bulk email
param (
[String] $From = $( Read-Host "Enter the SAM Account of the sender (example: dept1user1): " ),
[String] $To = $( Read-Host "Enter the SAM Account of the receiver (example: dept1user1): " ),
[String] $Type = $( Read-Host "Enter the type of media you want or 'ALL' (example: Facebook): " ),
[String] $Prefix = $( Read-Host "Enter prefix that will be used for each email: (example: TEST): " ),
[int] $numEmails = $( Read-Host "Enter the number of each media type you want: " ))
Import-Module ActiveDirectory
$allTypes = @($Type)
$localFrom = (Get-AdUser $From).Name+' <'+(Get-AdUser $From).UserPrincipalName+'>'
$localTo = (Get-AdUser $To).Name+' <'+(Get-AdUser $To).UserPrincipalName+'>'
$smtp = new-object Net.Mail.SmtpClient("localhost")
For ($i=1;$i -le $numEmails;$i++)
{
foreach ($singleType in $allTypes)
{
$formattedType = (Get-Culture).TextInfo.ToTitleCase($singleType.ToLower())
$msg = new-object Net.Mail.MailMessage
$msg.From = $localFrom
$msg.To.Add($localTo)
$msg.subject = $Prefix+" "+$singleType+" "+$i
$msg.body = $Prefix+" "+$singleType+" "+$i
if ($formattedType -eq "Chatter2")
{
$msg.Headers.Add("References", "<[email protected]>")
}
else
{
$msg.Headers.Add("X-example-Spam-Details", "rule=notspam policy=default score=0 spamscore=0 suspectscore=5 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701110249")
}
$smtp.Send($msg)
}
}
Send email
function Send-Messages
{
param (
[String] $From = $( Read-Host "Enter the SAM Account of the sender (example: dept1user1): " ),
[String] $To = $( Read-Host "Enter the SAM Account of the receiver (example: dept1user1): " ),
[String] $SubjectPrefix = $( Read-Host "Enter prefix that will be used for each email's subject: (example: TEST): " ),
[String] $BodyPrefix = $( Read-Host "Enter prefix that will be used for each email's body: (example: TEST): " ),
[int] $numEmails = $( Read-Host "Enter the number of each media type you want: " ))
Import-Module ActiveDirectory
$localFrom = (Get-AdUser $From).Name+' <'+(Get-AdUser $From).UserPrincipalName+'>'
$localTo = (Get-AdUser $To).Name+' <'+(Get-AdUser $To).UserPrincipalName+'>'
$smtp = new-object Net.Mail.SmtpClient("localhost")
For ($i=1;$i -le $numEmails;$i++)
{
$msg = new-object Net.Mail.MailMessage
$msg.From = $localFrom
$msg.To.Add($localTo)
$msg.subject = $SubjectPrefix + " " + $i
$msg.body = $BodyPrefix + " " + $i
$smtp.Send($msg)
}
}
Send-Messages -From auser1 -To auser2 -SubjectPrefix "Keyword00A" -BodyPrefix "Keyword00A" -numEmails 50
Send-Messages -From auser1 -To auser2 -SubjectPrefix "Keyword00B" -BodyPrefix "Keyword00B" -numEmails 50
Send-Messages -From auser3 -To auser4 -SubjectPrefix "Keyword01A" -BodyPrefix "Keyword01A" -numEmails 50
Send-Messages -From auser3 -To auser4 -SubjectPrefix "Keyword01B" -BodyPrefix "Keyword01B" -numEmails 50
# Whitelist Rule
Send-Messages -From auser1 -To auser2 -SubjectPrefix "Hello" -BodyPrefix "Keyword00A" -numEmails 50
# Pre-approved Content
Send-Messages -From auser1 -To auser2 -SubjectPrefix "Pre-approved" -BodyPrefix "Keyword00A is good" -numEmails 50
# Random message for matching sampling rule
Send-Messages -From auser1 -To auser4 -SubjectPrefix "Random" -BodyPrefix "No Keyword. For Sampling." -numEmails 50
Update IP address
# On Exchange PowerShell:
# Enable-PSRemoting -Force
#
# On Dev Box PowerShell:
# Set-Item wsman:\localhost\Client\TrustedHosts -value dc1
# Set-ExecutionPolicy RemoteSigned
param(
[switch] $EnableRemoteRun = $false,
[switch] $DisableProxyIPUpdate = $false)
$Username = "administrator"
$Password = "P@ssw0rd"
$FortivaQATestLocation = "HKLM:\Software\Wow6432Node\Fortiva\QATest"
$dc1Hostname = "dc1"
# Get IP addresses
$LocalIPAddress = (Test-Connection -ComputerName (hostname) -Count 1).IPV4Address.IPAddressToString
$ExchangeIPAddress = (Test-Connection -ComputerName $dc1Hostname -Count 1).IPV4Address.IPAddressToString
$EnableLocalRunName = "EnableLocalRun"
# Hash table for storing necessary Registry value
$RegistryValues = @{
"ApplianceIP" = $LocalIPAddress;
"WebUIURL" = "http://"+ $LocalIPAddress +"/web.ui";
"RestAPIUrl" = "http://" + $LocalIPAddress;
"PersonalArchiveUIRoute" = "http://"+ $LocalIPAddress +"/web.ui/archive/personal-archive/";
"SupervisionUIRoute" = "http://"+ $LocalIPAddress +"//web.ui/archive/supervision/";
$EnableLocalRunName = "http://localhost";
}
foreach ($h in $RegistryValues.GetEnumerator())
{
Set-ItemProperty -Path $FortivaQATestLocation -Name $h.Name -Value $h.Value
}
if ($EnableRemoteRun -eq $true)
{
Remove-ItemProperty -Path $FortivaQATestLocation -Name $EnableLocalRunName
}
if ($DisableProxyIPUpdate -eq $true)
{
return
}
$HostFileContent = @"
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
$LocalIPAddress appliance appliance.qa.examplearchiving.net
$ExchangeIPAddress dc1.qa.examplearchiving.net
"@
$SecuredPassword = ConvertTo-SecureString $Password -AsPlainText -Force
$ExchangeCred = New-Object System.Management.Automation.PSCredential ($Username, $SecuredPassword)
Invoke-Command -ComputerName $dc1Hostname -ScriptBlock { "$($args[0])" | Out-File 'C:\Windows\System32\drivers\etc\hosts' -Encoding ascii} -argumentlist $HostFileContent -Credential $ExchangeCred
Write-Output "Updated Host File"
Invoke-Command -ComputerName $dc1Hostname -ScriptBlock { ipconfig /flushdns } -Credential $ExchangeCred
Write-Output "Cleared DNS Cache"
Invoke-Command -ComputerName $dc1Hostname -ScriptBlock { iisreset /STOP } -Credential $ExchangeCred
Write-Output "Exchange IIS Stopped"
# Try Starting it twice to advoid random failure
Invoke-Command -ComputerName $dc1Hostname -ScriptBlock { iisreset /START } -Credential $ExchangeCred
Invoke-Command -ComputerName $dc1Hostname -ScriptBlock { iisreset /START } -Credential $ExchangeCred
Write-Output "Exchange IIS Started"