Skip to content

Instantly share code, notes, and snippets.

View Apoc70's full-sized avatar

Thomas Stensitzki Apoc70

View GitHub Profile
@Apoc70
Apoc70 / Update-UPN.ps1
Last active October 25, 2021 07:00
Update UPN suffix for all users in preparation Azure AD Connect
# Update the User Principal Name for all User Objects
$CustomDomain = "mcsmemail.de"
# Add custom domain as suffix first
Get-ADForest | Set-ADForest -UPNSuffixes @{add=$CustomDomain}
# Update all user objects
Get-ADUser -Filter * -Properties SamAccountName | ForEach-Object { Set-ADUser $_ -UserPrincipalName ($_.SamAccountName + "@$($CustomDomain)" )}
@Apoc70
Apoc70 / Clear-ADCDisabledMail.ps1
Last active October 25, 2021 12:56
This scripts clears the attribute legacyExchangeDN if set to ADCDisabledMail
# This script clears the legacyExchangeDN attribute of AD objects if the attribute is set to ADCDisabledMail
# Active Directory search base, adjust as needed for your AD
$SearchBase = 'DC=VARUNAGROUP,DC=DE'
# Our search filter
$Filter = 'legacyExchangeDN -eq "ADCDisabledMail"'
$csvFilename = 'ADCDisabledMail-Users.csv'
# Search for user objects matching the filter in the defined search base
@Apoc70
Apoc70 / nginx.conf
Created August 1, 2022 18:34
Partial nginx.conf file for an Exchange 2019 reverse proxy configuration
user www-data;
worker_processes auto;
pid /run/nginx.pid;
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;
load_module modules/ngx_stream_lua_module.so;
load_module modules/ngx_http_headers_more_filter_module.so;
events {
@Apoc70
Apoc70 / Create-TestUsers.ps1
Created August 29, 2022 14:18
A simple script fro creating test user accounts in AD.
# Number of user accounts to create
$UserCount = 5
$RandomPassword = $true
$DefaultPassword = 'Pa55w.rd'
# User name prefix
# New user object will be named TestUser1, TestUser2, ...
$TestUserPrefix = 'TestUser'
# User object properties
$GivenName = 'Test'
@Apoc70
Apoc70 / Add-EXOSmtpGatewayConnectors.ps1
Created February 5, 2023 08:43
This PowerShell script creats an Exchange Online inbound and outbound connector, and adds a transport rulle for the outbound connector.
# Name of the on-premises SMTP gateway
$GatewayName = 'NoSpamProxy'
# TLS certificate common name for incoming connection to EOP
$InboundTlsCN = 'smpto.varunagroup.de'
# TLS certificate common name for outgoing connection to EOP
$OutboundTlsCN = 'smpto.varunagroup.de'
# Fully qualified domain name (FQDN) of the on-premises SMTP gateway
@Apoc70
Apoc70 / MessageModify.cs
Created March 10, 2023 17:24
Example for intercepting email messages in an Exchange 2010 transport queue
// AttachmentModify
// ----------------------------------------------------------
// Example for intercepting email messages in an Exchange 2010 transport queue
//
// The example intercepts messages sent from a configurable email address(es)
// and checks the mail message for attachments have filename in to format
//
// WORKBOOK_{GUID}
//
// Changing the filename of the attachments makes it easier for the information worker
# Fetch all mail users
$DomainNameFilter = '*varunagroup.de'
Get-MailUser -ResultSize Unlimited | ?{$_.ExternalEmailAddress -like $DomainNameFilter} | Sort-Object DisplayName | Select-Object DisplayName, PrimarySmtpAddress
# New B2B user email address
$newEmailAddress = "user@setebos-ag.com"
# Update primary SMTP address for a selected user
$B2BUserToUpdate = 'USER_varunagroup.de#EXT#'
Set-MailUser $B2BUserToUpdate -ExternalEmailAddress "SMTP:$newEmailAddress" -WindowsEmailAddress $newEmailAddress
# Get EXO mailboxes by size
Get-ExoMailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Get-ExoMailboxStatistics | Sort TotalItemSize -Descending | Format-Table DisplayName, TotalItemSize, ItemCount
@Apoc70
Apoc70 / Get-IisTlsBindings.ps1
Created October 25, 2023 13:28
Query the current IIS SSL Bindings and provide the IIS Site and bound certificate as output
# Original source: https://techstronghold.com/scripting/@rudolfvesely/powershell-script-to-get-all-iis-bindings-and-ssl-certificates/
# Updated the script for a sorted output on Exchange Servers
Import-Module -Name WebAdministration
Get-ChildItem -Path IIS:SSLBindings | Sort-Object Port | ForEach-Object -Process `
{
if ($_.Sites)
{
$certificate = Get-ChildItem -Path CERT:LocalMachine/My |