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
Read here about DbDataAdapter.Fill and its return value:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With