none
System.Object[] when trying to export PowerShell output in CSV file. RRS feed

  • Question

  • Hello, Could you please  help in correcting the output of below script?

    In the CSV file, output for Location field is shown as System.Object[].

    $Result=@() 
    $users = Get-MsolUser -All
    $Rcpt = $users | ForEach-Object{ Get-Mailbox $_.liveid | Select customattribute10}
    $users | ForEach-Object {
    $user = $_
    if ($user.StrongAuthenticationRequirements.State -ne $null){
    $mfaStatus = $user.StrongAuthenticationRequirements.State
    }else{
    $mfaStatus = "Disabled" }

       
    $Result += New-Object PSObject -property @{ 
    UserName = $user.DisplayName
    UserPrincipalName = $user.UserPrincipalName
    Location = $Rcpt
    MFAStatus = $mfaStatus
    }
    }
    $Result | Export-Csv Newfile.csv

    Wednesday, August 14, 2019 2:24 PM

All replies

  • We don't fix script in this forum.

    When exporting to  CSV collections have to be converted to strings before exporting.


    \_(ツ)_/

    Wednesday, August 14, 2019 4:01 PM
  • Output in the column is because this object contains multiple values.


    Wednesday, August 14, 2019 4:43 PM