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

Welcome Forums General PowerShell Q&A PowerShell script to list which user is in Office 365 and OnPremise ?

This topic contains 0 replies, has 1 voice, and was last updated by  IT Engineer 3 months, 3 weeks ago.

  • Author
    Posts
  • #140371

    Participant
    Topics: 16
    Replies: 17
    Points: 141
    Rank: Participant

    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.

The topic ‘PowerShell script to list which user is in Office 365 and OnPremise ?’ is closed to new replies.