When I run this from the PowerShell command line
Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100"
-Database "come" -outputas datarows
-Query "select count(*) from andplaywithus"
I get this output in the terminal.
Column1
-------
74
However when I put the database invocation into a loop
# Define a condition to control the loop
$counter = 0
$maxIterations = 1005 # Number of times to run the query
while ($counter -lt $maxIterations) {
$result = Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100" -Database "come" -outputas datarows -Query "select count(*) from andplaywithus"
Write-Host "Result: $($result)"
# Increment the counter to avoid an infinite loop
$counter++
# Optionally add a delay between iterations
Start-Sleep -Seconds 20
}
I get
Result: System.Data.DataRow
this might work
$result = Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100" -Database "come" -outputas datarows -Query "select count(*)as count from andplaywithus"
Write-Host "Result: $($result[0].count)"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744690871a4588202.html
评论列表(0条)