I am doing an export of mailboxes from Office 365. Some mailboxes the have the same primarysmtpaddress are active and also Inactive. I enter code here have the following code:
$MBX = import-csv "c:\retention\LegalHold\test.csv"
$MBX | Add-Member -MemberType NoteProperty -Name Retention -Value NoPolicy
$MBX | Add-Member -MemberType NoteProperty -Name NoMailbox -Value $False
$MBX | Add-Member -MemberType NoteProperty -Name IsInactiveMailbox -Value $null
$MBX | Add-Member -MemberType NoteProperty -Name PrimarySmtpAddress -Value $null
$count=0
$fullcount = ($mbx | measure-object).count
foreach ($M in $MBX){
$policy = $null
$count++
$search = $m.custodian.tostring()
Write-progress -activity "Checking Mailbox $count out of $fullcount --- $search " -percentcomplete (($count / $fullcount)*100) -status "Processing"
Try{
$ErrorActionPreference = 'Stop'
$Policy = Invoke-Command -scriptblock {Get-EXOMailbox $m.custodian -IncludeInactiveMailbox -properties primarysmtpaddress,inplaceholds,isinactivemailbox,LitigationHoldEnabled,LitigationHoldDuration,Office}
#$Policy = Invoke-Command -scriptblock {Get-Mailbox $m.name -IncludeInactiveMailbox}
#$m.MBXFound = $True
$m.IsInactiveMailbox = $Policy.IsInactiveMailbox -join ','
$m.PrimarySmtpAddress = $Policy.PrimarySmtpAddress -join ','
}Catch{$m.NoMailbox = "$True"}
}
$MBX | export-csv C:\retention\legalhold\test_check.csv -NoTypeInformation
Instead of outputting to the CSV like this:
I'd like to have the mailboxes with an active and inactive mailbox on separate lines like this:

