最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - powershell invoke-sqlcmd System.Data.DataRow - Stack Overflow

programmeradmin0浏览0评论

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)"
发布评论

评论列表(0)

  1. 暂无评论