如何计算powershell变量中的行数

Imm*_*tal 0 powershell

我有以下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  "
Run Code Online (Sandbox Code Playgroud)

我希望能够计算$ TotalPeople变量中的行数.有没有办法在powershell中做到这一点?

Sag*_*pre 6

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
Run Code Online (Sandbox Code Playgroud)