Skip to content

Bug report: CSV columns not written if it is not in the header row #5684

@jackylamhk

Description

@jackylamhk

Priority

(Medium) I'm annoyed but I'll live

Description

For example, if I call m365 aad user list -p id,accountEnabled,department -o csv and the department field is only set for some users and not the first user returned, the CSV writer discards the column entirely.

So if I run it with --debug, I can see that it correctly retrieves the property:

...
  {
    "id": "some-uuid-here",
    "accountEnabled": true,
    "department": null
  },
  {
    "id": "some-other-uuid",
    "accountEnabled": false,
    "department": "Department Name"
  }
...

Then it only writes the following CSV:

id,accountEnabled
some-uuid-here,true
some-other-uuid,false

And the department is stripped because the field isn't written to the header row. I can't set this ahead in the CSV as a workaround either, since it writes to the file instead of appending.

Steps to reproduce

Call the m365 aad user list command with properties that only exists for some users but not the others.

Expected results

A full CSV with all the requested fields in the output.

Actual results

The CSV only partially writes without some fields that aren't populated for all users.

Diagnostics

No response

CLI for Microsoft 365 version

v7.1.0

nodejs version

v21.1.0

Operating system (environment)

macOS

Shell

bash

cli doctor

No response

Additional Info

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions