Reputation: 3073
I am running an sql query that will save the result into a csv. The only thing in the csv is the return of a COUNT() function. Is there a way that I can save this number directly into a variable in powershell?
Upvotes: 2
Views: 2309
Reputation: 354576
If you want to get rid of the CSV you could use the SqlServerCmdletSnapin:
Add-PSSnapIn SqlServerCmdletSnapin100
(Invoke-Sqlcmd -server .\sqlexpress -database foo -query 'SELECT COUNT(...) FROM ...')[0]
Upvotes: 1
Reputation: 201672
Should be simple. Let's assume the CSV field is called Result
:
$result = (Import-Csv .\sqlout.csv).Result
Upvotes: 2