#Requires -Version 5.1 <# JbTecWiz Support Centre -- generated fix script Fault : Outlook cannot set up the account, or connects to the wrong server Fix : Check the DNS records the lookup depends on Source: https://jbtecwiz.com/support/win-office-autodiscover Run as : PowerShell Expect : 30 minutes Risk : low Reversible : yes WHEN THIS IS THE RIGHT FIX Setup fails from any network, or the log shows a lookup failing at the DNS steps. HOW TO UNDO IT Note the previous DNS values before changing them. DNS changes propagate on their own schedule, so allow time before judging. This script walks the fix one step at a time and asks before each one. Steps with no command are things you do yourself -- it prints those and waits. Run with -DryRun to print without executing. #> [CmdletBinding()] param( # Print every step and command without running anything. [switch]$DryRun, # Do not ask before each step. Read the script first if you use this. [switch]$Unattended ) $ErrorActionPreference = 'Stop' $script:Failed = 0 # - THIS SCRIPT WILL NOT RUN UNTIL YOU EDIT IT - # The commands below contain values only you can supply. Search the # script for each one, replace it, then delete this block. $script:MustEdit = @( 'yourdomain.com' # a placeholder domain 'yourdomain' # a placeholder hostname ) if ($script:MustEdit.Count) { Write-Host "" Write-Host ' This script needs editing before it can run.' -ForegroundColor Yellow Write-Host ' Replace each of these with a real value:' -ForegroundColor Yellow $script:MustEdit | ForEach-Object { Write-Host (" " + $_) -ForegroundColor Yellow } Write-Host "" Write-Host ' Then delete the $script:MustEdit block near the top.' Write-Host "" exit 2 } function Write-Rule { param([string]$Text) Write-Host '' Write-Host ('-' * 70) -ForegroundColor DarkGray if ($Text) { Write-Host $Text -ForegroundColor Cyan } } function Show-Prose { param([string]$Text, [string]$Colour = "Gray") if (-not $Text) { return } $words = $Text -split "\s+"; $line = " " foreach ($w in $words) { if (($line.Length + $w.Length) -gt 74) { Write-Host $line -ForegroundColor $Colour; $line = " " } $line += "$w " } if ($line.Trim()) { Write-Host $line -ForegroundColor $Colour } } function Invoke-Step { param( [int]$Number, [string]$Do, [string]$Why, [scriptblock]$Command, [switch]$Manual, [string]$Shell = "powershell" ) Write-Rule " Step $Number of 5" Show-Prose $Do "White" if ($Why) { Write-Host ""; Show-Prose $Why "DarkGray" } if ($Manual) { Write-Host '' Write-Host ' -> Do this yourself, then press Enter to carry on.' -ForegroundColor Yellow if (-not $Unattended -and -not $DryRun) { [void](Read-Host) } return } Write-Host '' foreach ($l in ($Command.ToString().Trim() -split "`n")) { Write-Host (" " + $l.Trim()) -ForegroundColor Green } Write-Host '' if ($DryRun) { Write-Host " (dry run -- not executed)" -ForegroundColor DarkGray; return } if (-not $Unattended) { $a = Read-Host " Run this step? [Y]es / [S]kip / [Q]uit" if ($a -match "^[Qq]") { Write-Host " Stopped at your request."; exit 0 } if ($a -match "^[Ss]") { Write-Host " Skipped." -ForegroundColor DarkGray; return } } try { & $Command } catch { $script:Failed++ Write-Host (" Step $Number failed: " + $_.Exception.Message) -ForegroundColor Red Show-Prose "The rest of the fix may depend on this. Read the write-up before carrying on." "Red" if (-not $Unattended) { $c = Read-Host " Carry on anyway? [y/N]" if ($c -notmatch "^[Yy]") { exit 1 } } } } Write-Rule Write-Host ' Outlook cannot set up the account, or connects to the wrong server' -ForegroundColor White Write-Host ' Check the DNS records the lookup depends on' -ForegroundColor Cyan Write-Host '' Write-Host ' Risk: low Reversible 30 minutes' Write-Rule if (-not $Unattended -and -not $DryRun) { $go = Read-Host ' Ready? [y/N]' if ($go -notmatch "^[Yy]") { Write-Host " Nothing was changed."; exit 0 } } Invoke-Step -Number 1 -Do 'Check the autodiscover record for the mail domain.' -Why 'For Microsoft 365 this should be a CNAME to autodiscover.outlook.com. An A record pointing at an old server, or no record at all, is the usual finding.' -Command { Resolve-DnsName autodiscover.yourdomain.com | Select-Object Name, Type, NameHost, IP4Address } Invoke-Step -Number 2 -Do 'Check whether anything is answering at the root of the domain on 443, since that step comes first.' -Why 'A marketing website at the domain root will answer the https root-domain probe and return HTML rather than autodiscover XML. Outlook has to time out on it before moving on, which is why setup can take minutes and then fail.' -Command { Test-NetConnection yourdomain.com -Port 443 | Select-Object RemoteAddress, TcpTestSucceeded } Invoke-Step -Number 3 -Do 'Check for an SRV record, which is the supported alternative when the root domain is in use.' -Command { Resolve-DnsName -Type SRV _autodiscover._tcp.yourdomain.com -ErrorAction SilentlyContinue } Invoke-Step -Number 4 -Do 'Run Microsoft''s remote analyser against the address, which tests the whole sequence from outside your network and reports each step.' -Command { Start-Process 'https://testconnectivity.microsoft.com/' } Invoke-Step -Number 5 -Do 'Correct the records at the DNS provider. Allow for the TTL before retesting, and remember that a negative answer can be cached too.' -Manual Write-Rule " Confirm it worked" Show-Prose 'The remote analyser passes, and a new profile sets up without manual settings.' 'White' Write-Rule if ($script:Failed -gt 0) { Write-Host (" Finished with " + $script:Failed + " failed step(s).") -ForegroundColor Yellow Show-Prose 'Read the full write-up at https://jbtecwiz.com/support/win-office-autodiscover' 'Yellow' } else { Write-Host ' Finished.' -ForegroundColor Green } Write-Host '' Show-Prose 'To undo: Note the previous DNS values before changing them. DNS changes propagate on their own schedule, so allow time before judging.' 'DarkGray' Write-Rule