Created
July 17, 2019 14:12
-
-
Save adamhancock/f913f6023422204bcc83158cdab39521 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
# This is the cmdlet you'll need to edit with your own domain name or email address | |
if(Get-Module MSOnline){ | |
write-host "Module already installed." | |
}else{ | |
Install-Module -Force MSOnline | |
} | |
$ScriptBlock = {Get-AntiPhishPolicy | Set-AntiPhishPolicy -ExcludedDomains "feedback.smileback.io"} | |
# Establish a Windows PowerShell session with Office 365. You'll be prompted for your Delegated Admin credentials | |
if(!$Cred){ | |
$Cred = Get-Credential | |
} | |
Connect-MsolService -Credential $Cred | |
$customers= Get-MsolPartnerContract -All | |
Write-Host "Found $($customers.Count) customers for this Partner." | |
# For each of the contracts (customers), run the specified report and output the information. | |
foreach ($customer in $customers) { | |
# Get the initial domain for the customer. | |
$InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where {$_.IsInitial -eq $true} | |
#subscriptions | |
$subscriptions = Get-MsolSubscription -TenantId $customer.TenantId | |
if($subscriptions.SkuPartNumber -match "ATP"){ | |
write-host $InitialDomain.Name "has ATP. Adding trusted domains." | |
# Construct the URL with the DelegatedOrg parameter. | |
$DelegatedOrgURL = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name | |
# Connect to your customers tenant and run the script block | |
Invoke-Command -ConnectionUri $DelegatedOrgURL -Credential $Cred -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection -ScriptBlock $ScriptBlock -HideComputerName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment