Getting System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError] when export-csv ?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 171
Joined: Wed Oct 12, 2011 10:52 am

Getting System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError] when export-csv ?

Post by ITEngineer » Wed Oct 30, 2019 3:14 pm

Hi All,

I'm not sure why I always get the result System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
, instead of the correct string without the curly brackets:
ProvisioningErrors : {ProxyAddresses}
ProvisioningErrors : {UserPrincipalName}
This is the script that I'm using wrapped in the Powershell remoting best practice I've learned so far.

Code: Select all

If (-not (Get-Module MSOnline) ) {
    Write-Host "No Microsoft Online PowerShell module installed" -WarningAction
    Try { Install-Module MSOnline -ErrorAction Stop; Import-Module MSOnline -ErrorAction Stop }
    Catch { Write-Warning "Unable to load Microsoft Office 365 module because $($Error[0])"; Exit }
}

Try {
	$UserCredential = Get-Credential
	Connect-MsolService -Credential $UserCredential

    Get-MsolDirSyncProvisioningError -ErrorCategory PropertyConflict | 
        Select DisplayName, 
        UserPrincipalName, 
        ObjectType, 
        LastDirSyncTime, 
        {$_.ProvisioningErrors}, 
        @{n='ProxyAddresses'; e={$_.ProxyAddresses -join ', '}}, 
        ImmutableId, 
        ObjectId | 
        Export-Csv -NoTypeInformation C:\RESULT\DirSync.csv

}
Catch { Write-Warning "Unable to execute PowerShell remoting session because $($Error[0])"; Exit }
The result in the .CSV ProvisioningErrors column will always be:
ProvisioningErrors
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError]
How to fix the ProvisioningErrors column so that it only exports the proper text without the curly brackets?

Thank you in advance.
/* IT Engineer */

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Getting System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError] when export-csv

Post by jvierra » Wed Oct 30, 2019 3:48 pm

This line:
{$_.ProvisioningErrors},
Must be:
@{n='ProvError';e={$_.ProvisioningErrors[0]},

User avatar
ITEngineer
Posts: 171
Joined: Wed Oct 12, 2011 10:52 am

Re: Getting System.Collections.Generic.List`1[Microsoft.Online.Administration.DirSyncProvisioningError] when export-csv

Post by ITEngineer » Wed Oct 30, 2019 5:59 pm

jvierra wrote:
Wed Oct 30, 2019 3:48 pm
This line:
{$_.ProvisioningErrors},
Must be:
@{n='ProvError';e={$_.ProvisioningErrors[0]},
Cool, thanks man for the pointer :-)
/* IT Engineer */

Locked