To simplify automated configuration, Microsoft also makes these IP addresses available in XML format downloadable directly from Microsoft. You can download this using PowerShell.
[xml]$xml = invoke-webrequest -uri https://go.microsoft.com/fwlink/?LinkId=533185Once you have downloaded the xml file, you can extract just the IP addresses for Exchange Online Protection.
$EopIP = (($xml.products.product | Where-Object name -eq "eop").addresslist | Where-Object type -eq "ipv4").address
Once you have that list of IP addresses, it's easy to configure a receive connector with that list of addresses.
Set-ReceiveConnector -Name O365 -RemoteIPRanges $EopIP