我的 powershell 脚本在我预期的输出之前打印了一个“1".为什么? [英] My powershell script is printing a '1' before my expected output. Why?
问题描述
我编写了一个简单的 powershell 脚本,用于检查 PSA 服务板中的票数并输出票数和与之相关的颜色.但是,我的脚本在结果之前打印了一个1".我对 powershell 很陌生,我似乎找不到可以打印这个的行.任何帮助,将不胜感激.谢谢
I wrote a simple powershell script that checks the number of tickets in a PSA service board and outputs the number of tickets and a color associated with it. However, my script is printing a '1' before the results. I am very new to powershell, and I can't seem to find the line that would print this. Any help would be appreciated. Thanks
$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
在此处阅读有关 DbDataAdapter.Fill 及其返回值的信息:
Read here about DbDataAdapter.Fill and its return value:
类型:System.Int32在数据集中成功添加或刷新的行数.这不包括受不返回行的语句影响的行.
Type: System.Int32 The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows.
这篇关于我的 powershell 脚本在我预期的输出之前打印了一个“1".为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!