In this post we will be looking at how we can list actual vs expected DNS records for a Microsoft 365 tenant with PowerShell.
Background
A Microsoft Office 365 Tenant requires certain DNS entries to be in place, for a verified domain, to ensure things like mail, collaboration and device management all work as expected. Your tenant will show you the Status of a domain that you have added to your tenant
- Navigate to Microsoft 365 admin center
- Navigate to Settings > Domains

When the page indicates Possible Service issues it means that you don’t have the DNS records configured that your tenant is expecting. Now – this may be totally by design for larger orgs who are running Hybrid Exchange, using an external mail protection service, running a Skype for Business Hybrid and a 3rd Party MDM solution. If you click on the Domain Name you will see more info

and clicking on the DNS Records tab will reveal more. An Error does not indicate the service is not working but merely that your tenant was expecting the appropriate Microsoft assigned DNS record being in place instead of your custom one.

Previously, the M365 Admin Centre would show the Actual vs Expected DNS records all on the same page. Today you have to click on each record to see what is programmed

This can become quite laborious, especially if you have lots of verified domains on your tenant that you wish to check the DNS records for.
The Script
We are using two cmdlets in the following script: –
- Resolve-DNSName
- Get-AzureADDomainServiceConfigurationRecord
We can use Resolve-DNSName to resolve the Actual DNS entry for a domain registered in our tenant and Get-AzureADDomainServiceConfigurationRecord to check the Expected DNS record from Microsoft
Example: –
Retrieve the Expected DNS CNAME record for sip.byteben.com from our tenant for the verified domain byteben.com
1 2 |
Connect-AzureAD Get-AzureADDomainServiceConfigurationRecord -Name byteben.com | Where-Object { ($_.Label -like "*sip*") -and ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "OfficeCommunicationsOnline") } | Select-Object -ExpandProperty CanonicalName |

Retrieve the Actual MX record for byteben.com using Googles DNS Server 8.8.8.8
1 |
Resolve-DNSName -Name byteben.com -Type MX -Server 8.8.8.8 | Select-Object -ExpandProperty NameExchange |

Prerequisites
- Global Administrator for your Tenant
- AzureAD Module
- MSOnline Module
- Get_MSOLDomainDNS.ps1
If you don’t specify the DNSServer parameter, the default Google DNS is used (8.8.8.8). Once you login to your tenant, the script will list all verified domains in a GridView. You can select multiple domains to check DNS entries.
You can also specify the colour of the Expected vs Actual DNS records and caught errors by modifying the following variables: –
$CustomRecordColor = “Cyan”
$MSRecordColor = “Yellow”
$ErrorColor = “Red”


M365/Get_MSOLDomainDNS.ps1 at main · byteben/M365 (github.com)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
<# =========================================================================== Created on: 23/11/2020 Created by: Ben Whitmore Organization: byteben.com Filename: Get_MSOLDomainDNS.ps1 =========================================================================== 1.202311.02 23/11/2020 Ben Whitmore @byteben.com Added 3 Functions to query existing DNS Records and Catch any errors 1.202311.01 23/11/2020 Ben Whitmore @byteben.com Initial Release .DESCRIPTION Script to check if the actual DNS records for verified domains are the expected DNS records Requires the following PowerShell Modules:- Install-Module -Name AzureAD / AzureADPreview Install-Module -Name MSOnline .EXAMPLE Get_MSOLDomainDNS.ps1 -DNSServer "8.8.8.8" .PARAMETER DNSServer Specify which DNS Server to use to lookup existing DNS records #> Param ( [Parameter(Mandatory = $False)] [String]$DNSServer = "8.8.8.8" ) Function Get_Custom_MXRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Resolve DNS Name for existing MX Record on Verified Domain Try { Resolve-DNSName -Name $Domain -Type MX -Server $DNSServer -Erroraction Stop | Out-Null Resolve-DNSName -Name $Domain -Type MX -Server $DNSServer | Select-Object -ExpandProperty NameExchange -Erroraction Stop } Catch { Write-Host "Error getting MX Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_TXTRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Resolve DNS Name for existing TXT Record on Verified Domain Try { Resolve-DNSName -Name $Domain -Type TXT -Server $DNSServer -ErrorAction Stop | Out-Null Resolve-DNSName -Name $Domain -Type TXT -Server $DNSServer | Where-Object { $_.Strings -like "v=spf*" } | Select-Object -ExpandProperty Strings -ErrorAction Stop } Catch { Write-Host "Error getting TXT Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_AutoDiscoverRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $AutoDiscoverCNAME = "autodiscover.$($Domain)" #Resolve DNS Name for existing AutoDiscover CNAME Record on Verified Domain Try { Resolve-DNSName -Name $AutoDiscoverCNAME -Type CNAME -Server $DNSServer -ErrorAction Stop | Out-Null $Record = Resolve-DNSName -Name $AutoDiscoverCNAME -Type CNAME -Server $DNSServer | Where-Object { $_.Type -eq "CNAME" } | Select-Object -ExpandProperty NameHost -ErrorAction Continue If ($Record -eq $Null) { $Record = "Missing: Record Not Found" } $Record } Catch { Write-Host "Error getting Autodiscover CNAME Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_SIPRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $SIPCNAME = "sip.$($Domain)" #Resolve DNS Name for existing SIP CNAME Record on Verified Domain Try { Resolve-DNSName -Name $SIPCNAME -Type CNAME -Server $DNSServer -ErrorAction Stop | Out-Null $Record = Resolve-DNSName -Name $SIPCNAME -Type CNAME -Server $DNSServer | Where-Object { $_.Type -eq "CNAME" } | Select-Object -ExpandProperty NameHost -ErrorAction Continue If ($Record -eq $Null) { $Record = "Missing: Record Not Found" } $Record } Catch { Write-Host "Error getting SIP CNAME Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_LyncDiscoverRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $LyncDiscoverCNAME = "lyncdiscover.$($Domain)" #Resolve DNS Name for existing AutoDiscover CNAME Record on Verified Domain Try { Resolve-DNSName -Name $LyncDiscoverCNAME -Type CNAME -Server $DNSServer -ErrorAction Stop | Out-Null $Record = Resolve-DNSName -Name $LyncDiscoverCNAME -Type CNAME -Server $DNSServer | Where-Object { $_.Type -eq "CNAME" } | Select-Object -ExpandProperty NameHost -ErrorAction Continue If ($Record -eq $Null) { $Record = "Missing: Record Not Found" } $Record } Catch { Write-Host "Error getting LyncDiscover CNAME Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_SIPTLSRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $SIPTLSSRV = "_sip._tls.$($Domain)" #Resolve DNS Name for existing SIP TLS Record on Verified Domain Try { Resolve-DNSName -Name $SIPTLSSRV -Type SRV -Server $DNSServer -ErrorAction Stop | Out-Null Resolve-DNSName -Name $SIPTLSSRV -Type SRV -Server $DNSServer | Where-Object { $_.Type -eq "SRV" } | Select-Object Name, Port, Priority, Weight -ErrorAction Stop } Catch { Write-Host "Error getting SIP TLS SRV Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_SIPFederationTLSRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $SIPFederationTLSSRV = "_sipfederationtls._tcp.$($Domain)" #Resolve DNS Name for existing SIP Federation TLS Record on Verified Domain Try { Resolve-DNSName -Name $SIPFederationTLSSRV -Type SRV -Server $DNSServer -ErrorAction Stop | Out-Null Resolve-DNSName -Name $SIPFederationTLSSRV -Type SRV -Server $DNSServer | Where-Object { $_.Type -eq "SRV" } | Select-Object Name, Port, Priority, Weight -ErrorAction Stop } Catch { Write-Host "Error getting SIP Federation TLS SRV Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_EnterpriseRegistrationRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $EnterpriseRegistrationCNAME = "enterpriseregistration.$($Domain)" #Resolve DNS Name for existing Enterprise Registration CNAME Record on Verified Domain Try { Resolve-DNSName -Name $EnterpriseRegistrationCNAME -Type CNAME -Server $DNSServer -ErrorAction Stop | Out-Null $Record = Resolve-DNSName -Name $EnterpriseRegistrationCNAME -Type CNAME -Server $DNSServer | Where-Object { $_.Type -eq "CNAME" } | Select-Object -ExpandProperty NameHost -ErrorAction Continue If ($Record -eq $Null) { $Record = "Missing: Record Not Found" } $Record } Catch { Write-Host "Error getting Enterprise Registration CNAME Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } Function Get_Custom_EnterpriseEnrollmentRecord { Param ( [Parameter(Mandatory = $True)] [String]$Domain, [String]$DNSServer ) #Build Record Parameter $EnterpriseEnrollmentCNAME = "enterpriseenrollment.$($Domain)" #Resolve DNS Name for existing Enterprise Enrollment CNAME Record on Verified Domain Try { Resolve-DNSName -Name $EnterpriseEnrollmentCNAME -Type CNAME -Server $DNSServer -ErrorAction Stop | Out-Null $Record = Resolve-DNSName -Name $EnterpriseEnrollmentCNAME -Type CNAME -Server $DNSServer | Where-Object { $_.Type -eq "CNAME" } | Select-Object -ExpandProperty NameHost -ErrorAction Continue If ($Record -eq $Null) { $Record = "Missing: Record Not Found" } $Record } Catch { Write-Host "Error getting Enterprise Enrollment CNAME Record for $Domain. Error: $($Error[0].Exception.Message)" -ForegroundColor $ErrorColor } } #Set Colour Preference $CustomRecordColor = "Cyan" $MSRecordColor = "Yellow" $ErrorColor = "Red" #Get Credentials to perform connection to MSOnline and AzureAD $Credentials = Get-Credential #Import Modules - AzureADPreview can be substituted for AzureAD Import-Module AzureAD #Import-Module AzureADPreview Import-Module MSOnline #Connect to Services Connect-MsolService -Credential $Credentials | Out-Null Connect-AzureAD -Credential $Credentials | Out-Null #Get a list of Verified Domains for the tenant Write-Host "Enumerating Verified Domains..." -ForegroundColor Green $VerifiedDomains = Get-MsolDomain | Where-Object { ($_.Status -eq 'Verified') -and (!($_.Name -like "*onmicrosoft.com")) } | Sort-Object Name | Out-GridView -Title 'Choose a Verfied Domain(s):' -PassThru If ($VerifiedDomains -eq $Null) { Write-Host "No Verified Domains were selected or the operation was cancelled by the user" -ForegroundColor $ErrorColor Exit 1 } else { Write-Host "The following Verified Domains were selected:" -ForegroundColor Green Foreach ($Domain in $VerifiedDomains) { Write-Host $Domain.Name | Out-Host } Write-Host "Checking DNS Records for selected Domains..." -ForegroundColor Green Foreach ($Domain in $VerifiedDomains) { Write-Host "--------------------------------------" -ForegroundColor Green Write-Host $Domain.Name -ForegroundColor Green Write-Host "--------------------------------------" -ForegroundColor Green #Start Checking Records Write-Host "--------------------------------------" -ForegroundColor White Write-Host "Exchange Online Records" -ForegroundColor White Write-Host "--------------------------------------" -ForegroundColor White #Check MX Record Write-Host "MX Record for Verfied Domain is:" $Custom_MXRecordResult = Get_Custom_MXRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_MXRecordResult -ForegroundColor $CustomRecordColor #Get Expected MX Record Write-Host "Expected MX Record for Verfied Domain is:" Try { $MS_MXRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { $_.RecordType -eq "MX" } | Select-Object -ExpandProperty MailExchange -ErrorAction Stop Write-Host $MS_MXRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected MX Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check TXT Record Write-Host "TXT Record for Verfied Domain is:" Try { $Custom_TXTRecordResult = Get_Custom_TXTRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_TXTRecordResult -ForegroundColor $CustomRecordColor } Catch { Write-Host "Could not verify TXT Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Get Expected TXT Record Write-Host "Expected TXT Record for Verfied Domain is:" Try { $MS_TXTRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { $_.RecordType -eq "TXT" } | Select-Object -ExpandProperty Text -ErrorAction Stop Write-Host $MS_TXTRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected TXT Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check Autodiscover CNAME Record Write-Host "Autodiscover CNAME Record for Verfied Domain is:" $Custom_AutoDiscoverRecordResult = Get_Custom_AutoDiscoverRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_AutoDiscoverRecordResult -ForegroundColor $CustomRecordColor #Get Expected Autodiscover CNAME Record Write-Host "Expected Autodiscover CNAME Record for Verfied Domain is:" Try { $MS_AutoDiscoverRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "Email") } | Select-Object -ExpandProperty CanonicalName -ErrorAction Stop Write-Host $MS_AutoDiscoverRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected AutoDiscover CNAME Record for $($Domain.Name)" -ForegroundColor $ErrorColor } Write-Host "--------------------------------------" -ForegroundColor White Write-Host "Skype for Business Records" -ForegroundColor White Write-Host "--------------------------------------" -ForegroundColor White #Check SIP CNAME Record Write-Host "SIP CNAME Record for Verfied Domain is:" $Custom_SIPRecordResult = Get_Custom_SIPRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_SIPRecordResult -ForegroundColor $CustomRecordColor #Get Expected SIP CNAME Record Write-Host "Expected SIP CNAME Record for Verfied Domain is:" Try { $MS_SIPRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "*sip*") -and ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "OfficeCommunicationsOnline") } | Select-Object -ExpandProperty CanonicalName -ErrorAction Stop Write-Host $MS_SIPRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected SIP CNAME Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check LyncDiscover CNAME Record Write-Host "LyncDiscover CNAME Record for Verfied Domain is:" $Custom_LyncDiscoverRecordResult = Get_Custom_LyncDiscoverRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_LyncDiscoverRecordResult -ForegroundColor $CustomRecordColor #Get Expected LyncDiscover CNAME Record Write-Host "Expected LyncDiscover CNAME Record for Verfied Domain is:" Try { $MS_LyncDiscoverRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "*lyncdiscover*") -and ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "OfficeCommunicationsOnline") } | Select-Object -ExpandProperty CanonicalName -ErrorAction Stop Write-Host $MS_LyncDiscoverRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected LyncDiscover CNAME Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check SIP TLS SRV Record Write-Host "SIP TLS SRV Record for Verfied Domain is:" $Custom_SIPTLSRecordResult = Get_Custom_SIPTLSRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_SIPTLSRecordResult -ForegroundColor $CustomRecordColor #Get Expected SIP TLS SRV Record Write-Host "Expected SIP TLS SRV Record for Verfied Domain is:" Try { $MS_SIPTLSRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "_sip._tls*") -and ($_.RecordType -eq "SRV") -and ($_.SupportedService -eq "OfficeCommunicationsOnline") } | Select-Object NameTarget, Port, Priority, Protocol, Service, Weight -ErrorAction Stop Write-Host $MS_SIPTLSRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected SIP TLS SRV Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check SIP Federation TLS SRV Record Write-Host "SIP TLS SRV Record for Verfied Domain is:" $Custom_SIPFederationTLSRecordResult = Get_Custom_SIPFederationTLSRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_SIPFederationTLSRecordResult -ForegroundColor $CustomRecordColor #Get Expected SIP Federation TLS SRV Record Write-Host "Expected SIP Federation TLS SRV Record for Verfied Domain is:" Try { $MS_SIPFederationTLSRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "_sipFederationtls*") -and ($_.RecordType -eq "SRV") -and ($_.SupportedService -eq "OfficeCommunicationsOnline") } | Select-Object NameTarget, Port, Priority, Protocol, Service, Weight -ErrorAction Stop Write-Host $MS_SIPFederationTLSRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected SIP Federation TLS SRV Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Start Checking Records Write-Host "--------------------------------------" -ForegroundColor White Write-Host "Basic Mobility & Security Records" -ForegroundColor White Write-Host "--------------------------------------" -ForegroundColor White #Check Enterprise Registration Record Write-Host "Enterprise Registration Record for Verfied Domain is:" $Custom_EnterpriseRegistrationRecordResult = Get_Custom_EnterpriseRegistrationRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_EnterpriseRegistrationRecordResult -ForegroundColor $CustomRecordColor #Get Expected Enterprise Registration Record Write-Host "Expected Enterprise Registration Record for Verfied Domain is:" Try { $MS_EnterpriseRegistrationRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "enterpriseregistration*") -and ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "Intune") } | Select-Object -ExpandProperty CanonicalName -ErrorAction Stop Write-Host $MS_EnterpriseRegistrationRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected Enterprise Registration Record for $($Domain.Name)" -ForegroundColor $ErrorColor } #Check Enterprise Enrollment Record Write-Host "Enterprise Enrollment Record for Verfied Domain is:" $Custom_EnterpriseEnrollmentRecordResult = Get_Custom_EnterpriseEnrollmentRecord -Domain $Domain.Name -DNSServer $DNSServer Write-Host $Custom_EnterpriseEnrollmentRecordResult -ForegroundColor $CustomRecordColor #Get Expected Enterprise Enrollment Record Write-Host "Expected Enterprise Enrollment Record for Verfied Domain is:" Try { $MS_EnterpriseEnrollmentRecordResult = Get-AzureADDomainServiceConfigurationRecord -Name $Domain.Name | Where-Object { ($_.Label -like "enterpriseenrollment*") -and ($_.RecordType -eq "CNAME") -and ($_.SupportedService -eq "Intune") } | Select-Object -ExpandProperty CanonicalName -ErrorAction Stop Write-Host $MS_EnterpriseEnrollmentRecordResult -ForegroundColor $MSRecordColor } Catch { Write-Host "Could not verify expected Enterprise Enrollment Record for $($Domain.Name)" -ForegroundColor $ErrorColor } } } #Disconect remote PowerShell session Disconnect-AzureAD -Confirm:$False |
If you want to make suggestions please reach out on Twitter or Fork the script on GitHub. Thanks.