Hello there,
Use the Get-AcceptedDomain cmdlet to view the configuration information for the accepted domains in your organization.
https://learn.microsoft.com/en-us/powershell/module/exchange/get-accepteddomain?view=exchange-ps
Here is the simple PowerShell script to get all whitelisted domains in Azure AD.
$scriptpath = $MyInvocation.MyCommand.Path
#Get the current directory of the file stored.
$dir = Split-Path $scriptpath
#Get current date
$date = (get-date -f dd-MM-yyyy-hhmmss)
#Set filename to store the output
$Outfile = "$dir\Whitelisteddomains-"+$date+".csv"
#connect to Azure AD (assuming,the AzureADPreview, for now, is being installed.)
Connect-AzureAD
#List all B2B domains based on the condition
$data = (Get-AzureADPolicy | ? {$_.DisplayName -eq "B2BManagementPolicy" } | select definition)
#replace single quote with escape charcter and double quotes
$defs = $data.Definition.Replace('"',"""""")
$allowedDomains = $defs.Substring($defs.indexof("[")+1)
$allowedDomains = $allowedDomains.Substring(0,$allowedDomains.IndexOf("]"))
#revert back the quotes back to normal node to see the real output
$allowedDomains.Replace("""""","") | out-file $Outfile –Force
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–