Extra Columns in HTML Output From SQLcmd

Welcome Forums General PowerShell Q&A Extra Columns in HTML Output From SQLcmd

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 8 months ago.

  • Author
    Posts
  • #29022
    Yul

    Participant
    Topics: 2
    Replies: 3
    Points: 0
    Rank: Member

    Hi,

    I'm getting extra columns when trying to output an SQL query to HTML. I get RowError, RowState, Table, ItemArray & HasErrors along with with my actual query results. These looks like property values attached to the object created by Invoke-Sqlcmd.


    PS C:\> $myTable | ConvertTo-Html -as TABLE | Out-File C:\Test.htm
    PS C:\> Invoke-Expression C:\Test.htm

    Any ideas how I can strip those out?

    Thanks,

  • #29024

    Keymaster
    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    By default, ConvertTo-HTML converts ALL properties you give it into columns. Just use its -Prop parameter to specify the properties you want.

  • #29026
    Yul

    Participant
    Topics: 2
    Replies: 3
    Points: 0
    Rank: Member

    Ahh, so simple...

    Thank you very much!

  • #29030

    Participant
    Topics: 2
    Replies: 35
    Points: 58
    Team Member
    Rank: Member

    Hi!

    In case you use it elsewhere, just an FYI: Invoke-Expression is a bit risky, and can expose you to code injection.

    Invoke-Item would work in this example.

    Cheers!

The topic ‘Extra Columns in HTML Output From SQLcmd’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort