我寫了一個簡單的powershell腳本,用於檢查PSA服務板中的票數,並輸出票數和與之相關的顏色。但是,我的腳本在結果前打印了'1'。我對PowerShell非常陌生,而且我似乎無法找到能夠打印此行的行。任何幫助,將不勝感激。由於我的powershell腳本在我的預期輸出之前打印出'1'。爲什麼?
$SqlServer = "server"
$SqlCatalog = "database"
$SqlQuery = "SELECT COUNT(*) FROM v_rpt_Service WHERE Board_Name = 'Traige' AND Parent = ''"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlCatalog; uid = user; pwd = pass"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$value = $DataSet.Tables[0].Rows[0][0]
$color = "Red"
if($value -lt 4){
$color = "Yellow"
}
if($value -lt 1){
$color = "Green"
}
$obj = new-object System.object
add-member -inputobject $obj -membertype NoteProperty -Name Tickets -value $value
add-member -inputobject $obj -membertype NoteProperty -Name Color -value $color
$obj
$ SqlAdapter.Fill($ DataSet) Out-Null我猜想返回的行數是1 –
謝謝!如果您將您的評論作爲答案,我會將其標記爲正確!我沒有意識到填充數據集會自動打印。謝謝 ! –