我有以下powershell查询:
$sql = "select name, lastName, City, Address from Persons"
$TotalPeople = Invoke-Sqlcmd -ServerInstance $ResultsInstance -Database $ResultsDatabase -Query $sql
Write-Output "Total number of people run is $TotalPeople "
我希望能够计算$ TotalPeople变量中的行数。有没有办法在powershell中做到这一点?
答案 0 :(得分:5)
Invoke-sqlCmd返回一个数组。
因此,您只需使用count方法即可。
$sql = "select name, lastName, City, Address from Persons"
$TotalPeople = Invoke-Sqlcmd -ServerInstance $ResultsInstance -Database $ResultsDatabase -Query $sql
Write-Output "Total number of people run is "$TotalPeople.count