From bac57b17fe5f560744e68c032145f7530b6ba45b Mon Sep 17 00:00:00 2001 From: "Jeremy D. Berkleef" Date: Tue, 10 Aug 2021 10:04:01 -0300 Subject: [PATCH] Add mass deployment script for connector --- mass-deploy-spamfilter-connector.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 mass-deploy-spamfilter-connector.ps1 diff --git a/mass-deploy-spamfilter-connector.ps1 b/mass-deploy-spamfilter-connector.ps1 new file mode 100644 index 0000000..1ea8bba --- /dev/null +++ b/mass-deploy-spamfilter-connector.ps1 @@ -0,0 +1,25 @@ +# Set up command to run and vars for that command +$ScriptBlock = {New-InboundConnector -Name $connector_name -SenderDomains {smtp:*;1} -EFSkipIPs $spamfilterips -RestrictDomainsToCertificate $true -RequireTLS $true -TlsSenderCertificateName $hostname -CloudServicesMailEnabled $true} + +$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 +} \ No newline at end of file