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

Ask your 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.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post by ITEngineer »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

This line:
{$_.ProvisioningErrors},
Must be:
@{n='ProvError';e={$_.ProvisioningErrors[0]},
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post by ITEngineer »

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 */
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked