Search code examples
sqlpowershellinvoke-sqlcmd

Invoke-sqlcmd doesn't return data in rows


The Invoke-Sqlcmd doesn't return data in rows, it lists each item separately

This is the code that I'm using:

Invoke-Sqlcmd -ServerInstance "MyServer" -Query "SELECT * FROM [MyDB].[dbo].[MyTable]"

I get something like this:

Key         : 81839
Type        : DELETE
TableName   : InstList
ColumnName  : Key
ID          : 1092110700485
OldValue    : 5216268
NewValue    : 
UpdateDate  : 7/22/2019 12:06:30 PM
UserName    : test
FeatureName : Instruments

Key         : 81840
Type        : DELETE
TableName   : InstList
ColumnName  : Key
ID          : 2101128532011
OldValue    : 5289370
NewValue    : 
UpdateDate  : 7/22/2019 12:06:30 PM
UserName    : test
FeatureName : Instruments

Why does it not come out in rows?


Solution

  • Why does it not come out in rows?

    It is only matter or presenting data:

    Invoke-Sqlcmd -ServerInstance "MyServer" -Query "SELECT * FROM [MyDB].[dbo].[MyTable]" 
    | out-gridview
    

    or:

    Invoke-Sqlcmd -ServerInstance "MyServer" -Query "SELECT * FROM [MyDB].[dbo].[MyTable]" 
    | Format-Table -AutoSize