In my script, I am building a custom Powershell object which will be sent to Export-Csv. The receiving party has required that I include some blank columns (no data and no header) and I have no idea how to do that.
If the object looks like this:
$obj = [PSCustomObject][ordered]@{
EMPLOYER_EIN = '123456'
ACTION_CODE = 1
LAST_NAME = Smith
FIRST_NAME = John
MIDDLE_INITIAL = $null
EMPLOYEE_SSN = '111-11-1111'
}
How can I have the resulting .csv file's first row look like this:
EMPLOYER_EIN,ACTION_CODE,,LAST_NAME,FIRST_NAME,MIDDLE_INITIAL,,EMPLOYEE_SSN
Put another way, after I run Export-Csv, I want the file to look like this when opened in Excel:
| EMPLOYER_EIN | ACTION_CODE | LAST_NAME | FIRST_NAME | MIDDLE_INITIAL | EMPLOYEE_SSN | ||
|---|---|---|---|---|---|---|---|
| 123456 | 1 | Smith | John | 111-11-1111 |
Note the extra columns between action_code/last_name and middle_initial/employee_ssn. I am using PS 5.1 but could use 7 if necessary.
$headers = $obj | ConvertTo-Csv | Select-Object -First 1?$obj | Export-Csv C:\temp\test.csv -NoTypeInformation, then I get a normal .csv file. But I need the resulting file to have extra columns. I need a blank column between ACTION_CODE and LAST_NAME and another between MIDDLE_INITIAL and EMPLOYEE_SSN.[pscustomobject]@{ ' ' = $null }