Resolve Winmail.Dat Attachment Issue for all Office 365 Customer Tenants

Resolve Winmail.Dat Attachment Issue for all Office 365 Customer Tenants

Disable Winmail.dat for all Office 365 customer tenants

The issue with Winmail.dat attachments is something that comes up pretty often for Office 365 admins. Fortunately, it’s pretty simple to resolve (See our guide here to fix it for a single Office 365 tenant). Unfortunately, you’ll need to configure it on every tenant that you manage.

If you’re tired of fixing this issue for each Office 365 tenant, here’s a quick script that will resolve it across all customer Office 365 tenants in one go.

This script will connect to all Office 365 tenants using your delegated admin credentials, and run the Set-RemoteDomain cmdlet to disable TNEF on all customer tenants.

How to fix Winmail.dat issue in all delegated Office 365 tenants

  1. To run this script, copy and paste it into Visual Studio Code
  2. Save it as a PowerShell (.ps1) file
  3. Press F5 to run it
  4. Enter the credentials of an admin with delegated access to customer tenants. Note that this script does not support MFA. To ensure that you can run it with an MFA enabled account, you can whitelist your current static IP.
  5. Wait for it to completeFix Winmail.dat all Office 365 Tenants

Script for resolving Office 365 Winmail.dat issue in all customer tenants

$credential = Get-Credential
Connect-MsolService -Credential $credential

$customers = Get-msolpartnercontract -All 
foreach ($customer in $customers) {
    $InitialDomain = Get-MsolDomain -TenantId $customer.TenantId | Where-Object {$_.IsInitial -eq $true}
    Write-Host "Disabling Winmail.dat for $($customer.Name)" -ForegroundColor Green
    $DelegatedOrgURL = "https://outlook.office365.com/powershell-liveid?DelegatedOrg=" + $InitialDomain.Name
    $s = New-PSSession -ConnectionUri $DelegatedOrgURL -Credential $credential -Authentication Basic -ConfigurationName Microsoft.Exchange -AllowRedirection
    Import-PSSession $s -CommandName Set-RemoteDomain -AllowClobber

    Set-RemoteDomain Default -TNEFEnabled $false

    Remove-PSSession $s
Was this article helpful?

Related Articles

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *