PowerShell script to list which user is in Office 365 and OnPremise ?

People,

Can anyone here please assist me how to combine the below script into one so I can get the additional Column called Mailbox Location: OnPremise / Office 365 working correctly, so far it works, but everything is mentioned as OnPremise?

$filter = '(Enabled -eq $true) -and (msExchRecipientTypeDetails -ne 4) -and (homeMDB -ne "$null")'
$filterO365 = {($_.msExchRemoteRecipientType -eq 4) -and ($_.proxyAddresses -match "onmicrosoft.com") -and ($_.msExchRecipientDisplayType -eq ' -2147483642') -and ($_.msExchRecipientTypeDetails -eq '2147483648')}
$properties = @('homeMDB', 'mailNickName', 'mail', 'DisplayName', 'SamAccountName', 'ProxyAddresses', 'msExchRemoteRecipientType', 'proxyAddresses', 'msExchRecipientDisplayType', 'msExchRecipientTypeDetails' )

Get-ADUser -Filter $filter -Properties $properties |
	ForEach-Object {
		$smtpAddresses = ($_.ProxyAddresses | Where-Object { $_ -like "*smtp:*" }) -replace 'smtp:'
		New-Object -TypeName PSObject -Property ([ordered]@{
			MailboxLocation	= If (& $filterO365) {'Office 365'} Else {'OnPremise'}
			DisplayName		= $_.DisplayName
			mailNickName	= $_.mailNickName
			SamAccountName	= $_.SamAccountName
			mail			= $_.mail
			ProxyAddresses	= $smtpAddresses -join ';'
			HomeMDB			= $_.homeMDB.Split(',=')[1]
		})
	} | Export-Csv C:\Results.csv -NoTypeInformation

Thank you in advance.