SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
235 stars 67 forks source link

Export-GSSheet gets things mixed up when object properties aren't in the same order #292

Open FISHMANPET opened 4 years ago

FISHMANPET commented 4 years ago

Describe the bug Take this sample code:

$thing1 = [pscustomobject]@{
    thing1 = 'thing'
    thing2 = 'thing again'
}

$thing2 = [pscustomobject]@{
    thing2 = 'thing the third'
    thing1 = 'criss cross'
}

$things = @(
    $thing1
    $thing2
)

Export-GSSheet -SpreadsheetId $sheetid -Array $things -SheetName $sheetname

When printing $things to the terminal, Powershell can figure out that the objects are in a different order, but still display the object properly:

thing1      thing2
------      ------
thing       thing again
criss cross thing the third

Exporting that object to CSV with Export-CSV also properly puts criss cross in the first column.

However, Export-GSSheet gets confused and puts thing the third in the thing1 column and criss cross in the thing2 column.

image

Expected behavior criss cross should show up under thing1 not thing2