HasErrors is still present on the excel output even it is excluded in property.
PowerShell Info: Name Value
PSVersion 5.1.14393. PSEdition Desktop PSCompatibleVersions {1.0, 2.0, BuildVersion 10.0.14393 CLRVersion 4.0.30319. WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
I'm still getting the HasErrors field in excel.
Here is my PowerShell script: Invoke-Sqlcmd -Query "select @@version" -Database master -ServerInstance localhost | Select-Object -Property * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors | Export-Excel "D:\OutputFile.xlsx"
See screenshot of issue:

Export-Excel now supports DataTables, try this.
$DataTable = Invoke-Sqlcmd -Query "select @@Version" -Database master -ServerInstance localhost -OutputAs DataTables
Export-Excel "D:\OutputFile.xlsx" -InputObject $DataTable
That looks like you have run the same script more than once against the same file, and over written first column E, then D, then C, then B
Either delete the file before exporting or use -ClearSheet
if you remove the export is the right data coming out of the select.
@ili101 has also pointed out there is a better way when you have a datatable.
That looks like you have run the same script more than once against the same file, and over written first column E, then D, then C, then B Either delete the file before exporting or use -ClearSheet
if you remove the export is the right data coming out of the select.
@ili101 has also pointed out there is a better way when you have a datatable.
Hope you can share your script using the -ClearSheet. Thank you.
Export-Excel now supports DataTables, try this.
$DataTable = Invoke-Sqlcmd -Query "select @@Version" -Database master -ServerInstance localhost -OutputAs DataTables Export-Excel "D:\OutputFile.xlsx" -InputObject $DataTable
Exactly what I need. Thanks Mate!
Export-Excel "D:\OutputFile.xlsx" -clearsheet
or better
Export-Excel "D:\OutputFile.xlsx" -WorksheetName "Name" -ClearSheet