gpt4 book ai didi

powershell - 如何计算powershell变量中的行数

转载 作者:行者123 更新时间:2023-12-03 00:28:08 24 4
gpt4 key购买 nike

我有以下 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)"

关于powershell - 如何计算powershell变量中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com