Search code examples
sqlvariablespowershellcountsqlcmd

Saving result of COUNT() sql query into variable in powershell


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?


Solution

  • Should be simple. Let's assume the CSV field is called Result:

    $result = (Import-Csv .\sqlout.csv).Result