5 Replies Latest reply on Jan 24, 2018 4:45 AM by IanBaker

    powershell  - Netstat

    hansons

      Hi All,

       

      I'm looking for help on how to get the below working, and to keep a history of the results or have them displayed in a chart?

       

      $results = @()

      $results = netstat -ano | Select-String -Pattern '\s+(TCP|UDP)'

       

       

      $TimeWait = $results| where { $_.Line -like "*TIME_WAIT*0*"}

       

      #initialize counter for progress

      $SolarWindsCount = $TimeWait.count

       

      return $SolarWindsCount

      thanks for any help Hans

        • Re: powershell  - Netstat
          noeltz

          Hello,

           

          a script monitor has to return a statistic. This is a numeric value used to determine how the monitor compares to its set thresholds. This must be an integer value and is required. The message is optional.

          There is a limit of 10 statistic and message pairs for the script and each statistic and message output pair of your script requires a unique identifier.

          So you have to transform the status (running or not) into an integer value and output the statistic and message pair.

           

          For example:

           

          --------------------------------------------------------------------------------------------------------------------------

           

          $results = @()

          $results = netstat -ano | Select-String -Pattern '\s+(TCP|UDP)'

           

           

          $TimeWait = $results| where { $_.Line -like "*TIME_WAIT*0*"}

           

          #initialize counter for progress

          $SolarWindsCount = $TimeWait.count

           

          write-host "Statistic: $SolarWindsCount"

           

          --------------------------------------------------------------------------------------------------------------------------

           

          You can get more information here: The Basics of PowerShell (part 3)

           

           

            • Re: powershell  - Netstat
              hansons

              hi noeltz

               

              Thanks for the help how do I get this to run on the remote server "test1 192.168.2.2" and how can I get this to create a record of previous results ?

               

               

              thanks

               

              Hans

                • Re: powershell  - Netstat
                  IanBaker

                  Hi There,

                   

                  On the Powershell Application Component, there is an option to run remote (you will have to have winrm set up to accept the traffic and port 5958, and retsrt the winrm service after)

                  The statistic returned in the previous post should just record as part of the application.

                  This can then be reported upon, or extracted to Excel.

                  I have not go access to my systems today, but when in the office I can send you an example.

                    • Re: powershell  - Netstat
                      hansons

                      Hi IanBaker,

                       

                      it would be great if you could post up an example of how you would have this configured

                       

                      thanks

                       

                      Hans

                        • Re: powershell  - Netstat
                          IanBaker

                          Edit/Create Application using "Windows Powershell Monitor" component

                           

                          Rename the component name to something more meaningful (Time-Wait Count)

                           

                          Set the Credential for Monitoring (ideally an AD account that will work on the target machine)

                           

                          Set Execution Mode to Remote

                           

                          Hit the edit script and make sure that you set the Statistic and Message  by performing a write-host as follows:

                          {

                          Write-Host Statistic.0: $TimeWait.count

                          Write-Host Message.0: "Whatever you want in the message field"

                          }

                           

                          Then hit GET SCRIPT OUTPUT.   (If winrm is set up and any firewalls have been adjusted to allow Winrm Traffic), the script should run on the target you specified. This will generate "Script Output #1" This will be reported

                           

                          Now you can graph by adding in a report or page,  Custom Chart

                           

                          Select the criteria you need for the Graph under Advanced Selector > Component  - criteria is  Name is Time-Wait Count

                          You should be able to configure from there. If you need more than this just get back to me.