Compare commits

...

17 Commits

Author SHA1 Message Date
13f5b7c06b Fix missing } and unabbreviated 2021-11-04 11:27:31 +01:00
6b228fa6cb Add more text 2021-11-04 11:23:35 +01:00
210e74c6a4 Add permission checking functionality 2021-11-04 11:22:40 +01:00
778dcd93cf Add -ResultSize Unlimited to all Get-Mailbox calls 2021-11-04 10:07:47 +01:00
429240f403 Add mass mailbox locale changing functionality 2021-11-04 09:58:20 +01:00
c26a0d8b14 Fixed wording regarding Exchange Toolkit 2021-10-29 11:28:07 +02:00
c544743ce7 Rename alias-toolkit to exchange-toolkit because of added functionality 2021-10-29 11:25:35 +02:00
0970627a22 Add scope modifiers for no-language mode 2021-08-12 08:49:43 -03:00
eaf09b4d23 Fix ConnectorType 2021-08-12 08:39:37 -03:00
0318da6697 Update readme 2021-08-10 10:06:03 -03:00
bac57b17fe Add mass deployment script for connector 2021-08-10 10:04:01 -03:00
3801a16828 Add spamfilter deployment script 2021-08-09 09:42:48 -03:00
5a8031486b Replace verification logic with print statement 2021-05-05 08:51:56 -03:00
9a53092bf7 Fix emphasis on option 3 2021-05-03 09:00:17 -03:00
7f46f40dd0 Add general documentation and docs for alias-toolkit 2021-05-03 08:56:35 -03:00
585f3ada1b Remove more references to EXO-only mode 2021-05-03 08:56:05 -03:00
3e880672dd Remove Exchange Online only command from option 2 2021-05-03 08:55:26 -03:00
6 changed files with 303 additions and 119 deletions

48
Docs/exchange-toolkit.md Normal file
View File

@@ -0,0 +1,48 @@
# Exchange Toolkit
## How to use Exchange Toolkit
1. Download the script or clone this repository
2. Make sure the execution policy is set properly (Or run Set-ExecutionPolicy Bypass -Scope Process)
3. Run the script.
4. Follow the on-screen prompts.
> _If target is Exchange Server, run script from the Exchange Management Shell._
>
>_If target is Exchange Online, run from a PS session that has already connected to Exchange Online Management Shell._
## Exchange Toolkit Options
### 1. List contents of a .csv
Use this option to verify that your .csv file containing email addresses is formatted correctly. The output should look like:
> _Display Name_
>
> _Email Address 1_
>
> _Email Address 2_
>
> _Email Address 3_
If the email addresses are on a single line, your formatting isn't correct and the import will import all your addresses as a single email address.
### 2. Apply the contents of a .csv to the currently logged in Exchange session
Use this option to apply the email addresses when you've verified that the .csv is formatted correctly.
> ***This will apply the email addresses based on Display Name, so make sure that if display names were changed between environments, the .csv has been edited to reflect the changes.***
### 3. Create a .csv based on a search term
This option will create a .csv with the columns Displayname and EmailAddresses based on the search term given.
This uses `Get-Mailbox | Where-Object $_.EmailAddresses -like "$SearchTerm"`, so it will support wildcards.
> ***This won't give you a .csv you can apply by default, this is by design. You need to replace the spaces with ; in the EmailAddresses column. This was implemented to ensure double-checking no unwanted addresses are included into the import.***
### 4. Use the legacy search script and output the alias list to console.
This does the same as the above option, but outputs the results to console with some nice-ish formatting. This is an adaptation of search-email-addresses.
### 5. Export a series of mailboxes to .pst
This has only been tested against On-Prem Exchange.
This option will export the mailboxes found via the search term to a .pst. For some reason, Exchange requires a UNC path for the export.
### 6. Set mailbox locale based on a search term
This allows you to change a large number of mailboxes' language, time zone and date format settings in one go.
### 7. and 8. List mailbox permissions based on a search term
These allow you to list all permissions for mailboxes based on a search term or export them to .csv.

View File

@@ -1,3 +1,10 @@
# Exchange-Scripts
Various scripts used for management tasks (and migrations) on Exchange server
This repo contains various scripts used for management tasks (and migrations) on Exchange Server (and Exchange Online). You can click on the script name to see documentation for it.
# Scripts
- [**Exchange Toolkit**](Docs/exchange-toolkit.md) - Easy to use, menu-based script for automating multiple tedious tasks in Exchange (Online).
- **Spam Filter Deployment Script** - Script to create the Connector and Enhanced Filtering rule for a spam gateway.
- **Mass Spam Filter Deployment Script** - Script to use delegated Partner (CSP) domains and deploy Connector and Enhanced Filtering rule for a spam gateway.
- **List alias .csv contents** - _This has been integrated into Exchange Toolkit._
- **Search Email Addresses** - _This has been integrated into Exchange Toolkit._

View File

@@ -1,118 +0,0 @@
function Show-Menu {
param (
[string]$Title = 'Alias Toolkit by Jeremy Berkleef'
)
Clear-Host
Write-Host -ForegroundColor Green "================ $Title ================"
Write-Host "1: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '1' " -NoNewline
Write-Host "to list the contents of a .csv."
Write-Host "2: Press" -NoNewline
Write-Host -Foregroundcolor Cyan " '2' " -NoNewline
Write-Host "to apply the contents of a .csv to the currently logged in Exchange Online session."
Write-Host "3: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '3' " -NoNewline
Write-Host "to create a .csv file of aliases from Exchange based on a search term."
Write-Host "4: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '4' " -NoNewline
Write-Host "to use the legacy search script and output the alias list to console."
Write-Host "Q: Press" -NoNewline
Write-Host -ForegroundColor Red " 'Q' " -NoNewline
Write-Host "to quit."
}
do
{
Show-Menu
$selection = Read-Host "Please make a selection"
switch ($selection)
{
'1' {
#Ask where the .csv is
$CsvLocation = Read-Host -Prompt 'CSV path'
#Print a new line
Write-Host `n
#Read the .csv and print it to console
Import-Csv $CsvLocation | ForEach-Object {
Write-Host -Foregroundcolor Red -Backgroundcolor White (Write-Output $_.Displayname);
write-Host -foregroundcolor Green -Separator `n (Write-Output $_.EmailAddresses.Split(";"))
}
}
'2' {
#Ask where the .csv is and import the values into the Alias_List variable
$CsvLocation = Read-Host -Prompt 'CSV path'
$Alias_list = Import-Csv $CsvLocation
#Print a new line
Write-Host `n
#Read the .csv, apply the aliases and print the resulting aliases
Foreach ($Alias in $Alias_list) {
Set-Mailbox -Identity $Alias.Displayname -EmailAddresses $Alias.EmailAddresses.Split(";")
}
#Get the mailboxes from Exchange Online and print the email addresses to confirm the changes.
Foreach ($Alias in $Alias_list) {
$addresses = (Get-ExoMailbox -Identity $Alias.Displayname).EmailAddresses
if ($addresses -eq $Alias.EmailAddresses) {
Write-Host "$($Alias.Displayname)" -NoNewline
Write-Host -ForegroundColor Green " Success!"
}
else {
Write-Host "$($Alias.Displayname)" -NoNewline
Write-Host -ForegroundColor Red " FAILURE"
}
}
}
'3' {
#Ask the user what we're looking for and we're we're going to save the .csv
$searchTerm = Read-Host -Prompt 'Input search query'
$CsvSavePath = Read-Host -Prompt 'Input location to save .csv'
#List Aliases and select
get-mailbox | Where-Object {$_.EmailAddresses -like "$searchTerm"} | Select-Object Displayname,@{Name="EmailAddresses";Expression={$_.EmailAddresses}} | Export-Csv -NoTypeInformation $CsvSavePath
#Remind the user that they need to fix the csv formatting.
Write-Host -ForegroundColor Red -BackgroundColor Black "Please be sure to remember to format the .csv correctly before importing it back into an Exchange Server or Exchange Online"
Write-Host `n
Write-Host -BackgroundColor Black -ForegroundColor Blue "Before importing, delete the non-email addresses from the .csv and replace the spaces between addresses with ';'.`nThis is a safety measure to prevent applying an incompatible address."
}
'4' {
# Ask the user what we need to search for
$searchTerm = Read-Host -Prompt 'Input Query'
#List Aliases
get-mailbox | Where-Object {$_.EmailAddresses -like "$searchTerm"} |ForEach-Object{
$host.UI.Write("White", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
{
$address = $_.EmailAddresses[$i]
$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
if ($address.IsPrimaryAddress)
{
$host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
}
else
{
$host.UI.Write("Red", $host.UI.RawUI.BackGroundColor, "Alias`n")
}
}
}
}
}
Read-Host -Prompt 'Press Enter to Continue'
}
until ($selection -eq 'q')

View File

@@ -0,0 +1,8 @@
Connect-ExchangeOnline
# Options
$connector_name = 'Spamfilter Connector'
$hostname = 'spamgateway.aperturect.com'
$spamfilterips = {127.0.0.1}, {127.0.0.2}
# Create connector for spam filter and enable EF
New-InboundConnector -Name $using:connector_name -SenderDomains {smtp:*;1} -EFSkipIPs $using:spamfilterips -RestrictDomainsToCertificate $true -RequireTLS $true -TlsSenderCertificateName $using:hostname -CloudServicesMailEnabled $true -ConnectorType OnPremises

214
exchange-toolkit.ps1 Normal file
View File

@@ -0,0 +1,214 @@
function Show-Menu {
param (
[string]$Title = 'Exchange Toolkit by Jeremy Berkleef'
)
Clear-Host
Write-Host -ForegroundColor Green "================ $Title ================"
Write-Host "1: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '1' " -NoNewline
Write-Host "to list the contents of a .csv."
Write-Host "2: Press" -NoNewline
Write-Host -Foregroundcolor Cyan " '2' " -NoNewline
Write-Host "to apply the contents of a .csv to the currently logged in Exchange session."
Write-Host "3: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '3' " -NoNewline
Write-Host "to create a .csv file of aliases from Exchange based on a search term."
Write-Host "4: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '4' " -NoNewline
Write-Host "to use the legacy search script and output the alias list to console."
Write-Host "5: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '5' " -NoNewline
Write-Host "to export a list of mailboxes to .pst based on a search term."
Write-Host "6: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '6' " -NoNewline
Write-Host "to change mailbox locale/language based on a search term."
Write-Host "7: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '7' " -NoNewline
Write-Host "to list all mailbox permissions based on a search term."
Write-Host "8: Press" -NoNewline
Write-Host -ForegroundColor Cyan " '8' " -NoNewline
Write-Host "to list all mailbox permissions based on a search term and export to a .csv."
Write-Host "Q: Press" -NoNewline
Write-Host -ForegroundColor Red " 'Q' " -NoNewline
Write-Host "to quit."
}
do
{
Show-Menu
$selection = Read-Host "Please make a selection"
switch ($selection)
{
'1' {
#Ask where the .csv is
$CsvLocation = Read-Host -Prompt 'CSV path'
#Print a new line
Write-Host `n
#Read the .csv and print it to console
Import-Csv $CsvLocation | ForEach-Object {
Write-Host -Foregroundcolor Red -Backgroundcolor White (Write-Output $_.Displayname);
write-Host -foregroundcolor Green -Separator `n (Write-Output $_.EmailAddresses.Split(";"))
}
}
'2' {
#Ask where the .csv is and import the values into the Alias_List variable
$CsvLocation = Read-Host -Prompt 'CSV path'
$Alias_list = Import-Csv $CsvLocation
#Print a new line
Write-Host `n
#Read the .csv, apply the aliases and print the resulting aliases
Foreach ($Alias in $Alias_list) {
Set-Mailbox -Identity $Alias.Displayname -EmailAddresses $Alias.EmailAddresses.Split(";")
}
#Print the new values to console for verification
Write-Host -ForegroundColor Green -BackgroundColor White "New Values:"
#Get the mailboxes from Exchange and print the email addresses to confirm the changes.
Foreach ($Alias in $Alias_list) {
$addresses = (Get-Mailbox -ResultSize Unlimited -Identity $Alias.Displayname).EmailAddresses
Write-Host -Foregroundcolor Red -Backgroundcolor White (Write-Output $Alias.Displayname);
write-Host -foregroundcolor Green -Separator `n (Write-Output $addresses)
}
}
'3' {
#Ask the user what we're looking for and we're we're going to save the .csv
$searchTerm = Read-Host -Prompt 'Input search query'
$CsvSavePath = Read-Host -Prompt 'Input location to save .csv'
#List Aliases and select
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"} | Select-Object Displayname,@{Name="EmailAddresses";Expression={$_.EmailAddresses}} | Export-Csv -NoTypeInformation $CsvSavePath
#Remind the user that they need to fix the csv formatting.
Write-Host -ForegroundColor Red -BackgroundColor Black "Please be sure to remember to format the .csv correctly before importing it back into an Exchange Server or Exchange Online"
Write-Host `n
Write-Host -BackgroundColor Black -ForegroundColor Blue "Before importing, delete the non-email addresses from the .csv and replace the spaces between addresses with ';'.`nThis is a safety measure to prevent applying an incompatible address."
}
'4' {
# Ask the user what we need to search for
$searchTerm = Read-Host -Prompt 'Input Query'
#List Aliases
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"} |ForEach-Object{
$host.UI.Write("White", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
{
$address = $_.EmailAddresses[$i]
$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
if ($address.IsPrimaryAddress)
{
$host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
}
else
{
$host.UI.Write("Red", $host.UI.RawUI.BackGroundColor, "Alias`n")
}
}
}
}
'5' {
Write-Host -ForegroundColor Blue -BackgroundColor White "For exporting a single mailbox, prepend a * to the mailbox name (e.g. *mailbox@example.com)"
$searchTerm = Read-Host -Prompt "Search Query"
Write-Host -ForegroundColor Blue -BackgroundColor White "Path must be in UNC format for Exchange to export to."
$savePath = Read-Host -Prompt "Export Path"
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"}
Foreach ($mailbox in $mailboxes) {
#Concatenate the save path and the mailbox alias.
$exportPath = Join-Path $savePath $mailbox.Alias
New-MailboxExportRequest -Mailbox $mailbox -FilePath "$exportPath.pst"
}
}
'6' {
$searchTerm = Read-Host -Prompt "Input Query"
$targetLanguage = Read-Host -Prompt "Language to switch to (nl-NL for Dutch)"
$targetTimezone = Read-Host -Prompt "Time zone to switch to ("W. Europe Standard Time" for GMT -1)"
$targetDateFormat = Read-Host -Prompt "Date format to switch to (e.g. "d-M-yyy")"
#Search mailboxes and apply the changes
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"} | Set-MailboxRegionalConfiguration -Language "$targetLanguage" -TimeZone "$targetTimezone" -DateFormat "$targetDateFormat"
}
'7' {
$searchTerm = Read-Host -Prompt "Input Query"
#Get mailboxes from search term
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"}
#Create array to store the objects
[System.Collections.ArrayList]$permissionsArray = @()
#Get Permissions from mailboxes and create custom object
Write-Host "Getting permissions for $mailbox"
foreach ($mailbox in $mailboxes) {
$permissionsObject = [PSCustomObject]@{
displayname = $mailbox.DisplayName
emailAddress = $mailbox.PrimarySmtpAddress
sendOnBehalfOf = $mailbox.GrantSendOnBehalfTo
sendAs = Get-ADPermission $mailbox.identity | Where-Object {($_.ExtendedRights -like *Send-As*) -and -not ($_.User -like NT AUTHORITY\SELF) -and -not ($_.User -like s-1-5-21*)} | ForEach-Object {$_.User}
fullAccess = Get-MailboxPermission $mailbox.Identity | Where-Object {($_.IsInherited -eq $False) -and -not ($_.User -match NT AUTHORITY)} |Select-Object User,Identity,@{Name=AccessRights;Expression={$_.AccessRights}} | ForEach-Object {$_.User}
}
#Add the objects to the permissions array
$permissionsArray.Add($permissionsObject) | Out-Null
}
#Output a cool and nice table
$permissionsArray | Format-Table
Write-Host -ForegroundColor White -BackgroundColor Blue "Data is stored in the variable permissionsArray."
}
'8' {
$searchTerm = Read-Host -Prompt "Input Query"
$csvSavePath = Read-Host -Prompt ".csv save"
#Get mailboxes from search term
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "$searchTerm"}
#Create array to store the objects
[System.Collections.ArrayList]$permissionsArray = @()
#Get Permissions from mailboxes and create custom object
Write-Host "Getting permissions for $mailbox"
foreach ($mailbox in $mailboxes) {
$permissionsObject = [PSCustomObject]@{
displayname = $mailbox.DisplayName
emailAddress = $mailbox.PrimarySmtpAddress
sendOnBehalfOf = $mailbox.GrantSendOnBehalfTo
sendAs = Get-ADPermission $mailbox.identity | Where-Object {($_.ExtendedRights -like *Send-As*) -and -not ($_.User -like NT AUTHORITY\SELF) -and -not ($_.User -like s-1-5-21*)} | ForEach-Object {$_.User}
fullAccess = Get-MailboxPermission $mailbox.Identity | Where-Object {($_.IsInherited -eq $False) -and -not ($_.User -match NT AUTHORITY)} |Select-Object User,Identity,@{Name=AccessRights;Expression={$_.AccessRights}} | ForEach-Object {$_.User}
}
#Add the objects to the permissions array
$permissionsArray.Add($permissionsObject) | Out-Null
}
#Output a cool and nice table and output a .csv
$permissionsArray | Format-Table
$permissionsArray | Export-Csv -NoTypeInformation $csvSavePath
}
}
Read-Host -Prompt 'Press Enter to Continue'
}
until ($selection -eq 'q')

View File

@@ -0,0 +1,25 @@
# Set up command to run and vars for that command
$ScriptBlock = {New-InboundConnector -Name $using:connector_name -SenderDomains {smtp:*;1} -EFSkipIPs $using:spamfilterips -RestrictDomainsToCertificate $true -RequireTLS $true -TlsSenderCertificateName $using:hostname -CloudServicesMailEnabled $true -ConnectorType OnPremises}
$connector_name = 'Spamfilter Connector'
$hostname = 'spamgateway.aperturect.com'
$spamfilterips = {127.0.0.1}, {127.0.0.2}
# Establish a PowerShell session with Office 365. You'll be prompted for your Delegated Admin credentials
$Cred = Get-Credential
Connect-MsolService -Credential $Cred
# Locate .csv with targets
$CsvLocation = Read-Host -Prompt 'Tenants CSV path (use "Get-MsolPartnerContract -All | export-csv" and delete the rows you do not need'
$customers = Import-Csv $CsvLocation
Write-Host "Found $($customers.Count) customers in the .csv file."
# Go through the targets and execute $ScriptBlock
foreach ($customer in $customers) {
$InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where-Object {$_.IsInitial -eq $true}
Write-Host "Creating connector for $($Customer.Name)"
$DelegatedOrgURL = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name
Invoke-Command -ConnectionUri $DelegatedOrgURL -Credential $Cred -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection -ScriptBlock $ScriptBlock -HideComputerName
}