6 Replies Latest reply on Mar 11, 2019 9:12 AM by ctech291

    powershell monitor showing failure even though it ends with 'exit 0'?

    ctech291

      I have a fairly simple powershell script (see below) that ends with "exit 0".

       

      Yet when I test it I get a "Testing on node {node name}: failed with 'Unknown' status.

       

       

      Any idea why it is getting an 'Unknown' status?

       

      Thank you

       

       

      Powershell script that I'm running:

      function Get-DOSSqlData($connectionString, $SelectSql)
      {
      
      
          Write-Verbose 'Get-DOSSqlData: Starting'
      
      
          $connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
          $connection.Open()
          $command = $connection.CreateCommand()
          $command.CommandText = $SelectSql
          $command.CommandTimeout = 10
      
      
      
      
          $adapter = New-Object System.Data.SqlClient.SqlDataAdapter $command
          $dataset = New-Object System.Data.DataSet
          $adapter.Fill($dataset) | out-null
      
      
      
      
          If ($null -ne $dataset.Tables[0])
          {
              $table = $dataset.Tables[0]
          }
          ElseIf ($table.Rows.Count -eq 0)
          {
              $table = New-Object System.Collections.ArrayList
          }
      
      
          $connection.Close()
      
      
          Write-Verbose 'Get-DOSSqlData: Returning'
          return $table
      }
      
      $env:UserName
      $env:UserDomain
      $env:ComputerName
      
      Write-Host "testing"
      
      $metadataConnectionString = "Server=localhost;Database=master;Trusted_Connection=True;MultipleActiveResultSets=True;Connect Timeout=10"
      $result1 = Get-DOSSqlData $metadataConnectionString "SELECT getdate()"
      
      
      Write-Host $result1
      Write-Host "done"
      
      
      exit 0