Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何计算powershell变量中的行数_Powershell - Fatal编程技术网

如何计算powershell变量中的行数

如何计算powershell变量中的行数,powershell,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 " 我希望能够计算$T

我有以下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中是否有这样做的方法?

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

$TotalPeople.count?:)