Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

How to find number of columns returned from query in powershell

$
0
0
I want to find out number of columns returned from a query in a powershell script.As we will be passing a dynamic query which can retrieve only 2 columns or 5 columns or n columns based on user's choice.$SQLQuery = " select * from sysdatabases "$QueryResults = Invoke-Sqlcmd -Query $SQLQuery -ServerInstance Win7 -SuppressProviderContextWarningforeach ($row in $QueryResults){ $row.Item(0)}Can you please help on how to find number of columns returned from above query.

Viewing all articles
Browse latest Browse all 467

Trending Articles