Exchange Online PowerShell can display warnings as shown below.
To capture the warning in a script, use the WarningVariable parameter available on each command.
1 | $Warn = "" |
You can then read the variable specified by WarningVariable to get the warning output.
As a side note, Exchange Online previously used Remote PowerShell for connections. With that connection, this method could not capture warning output from Exchange Online PowerShell. At the time, the command itself had to run through Invoke-Command, with WarningVariable used to capture the warning. For example:
1 | $warn = "" |
Exchange Online now uses REST for connections, so this method can no longer be used.