Working with tables

This topic contains 13 replies, has 6 voices, and was last updated by  Rodrigo 1 week ago.

  • Author
    Posts
  • #83468

    Rodrigo
    Participant

    Hi,

    I have a powershell script that create a table with two columns. I would like use a conditional ( if ) and put de values searched into a news variables. See below:
    SinaldBm Cliente
    ——– ——-
    -19 16777472
    -20 16777728
    -19 16777984
    -19 16778240
    0.0 16778496
    -19 16778752
    -23 16779008
    -18 16779264
    -19 16779520
    -22 16779776
    -27 16780032
    -18 16780288
    -19 16780544
    -19 16780800
    -21 16781056
    -24 16781568
    -19 16781824
    -22 16782080
    -21 16782336
    -21 16782592
    0.0 16782848
    -22 16783104
    -23 16783360
    0.0 16783616
    -22 16783872
    -24 16784128
    -24 16784384
    -26 16784640
    -22 16784896
    -22 16785152
    -23 16785408
    -21 16785664
    -25 16785920

    I Need to show only combined data with value less or equal to -25. Ex:
    -26 16784640
    -25 16785920

    Thank you for advance...

    rc.

  • #83473

    Sergey Vasin
    Participant

    Hello.

    If the output of your script is object, then:

    your_script | where SinaldBm -le -25
    
    • #83474

      Rodrigo
      Participant

      Hi,

      My code is like below ( a part of)

      $column1 = @($strcli)
      $column2 = @($strnum)

      $i=0
      ($column1,$column2 | sort length)[1] |
      foreach {
      new-object psobject -property @{
      Cliente = $Column1[$i]
      SinaldBm = $column2[$i++]
      }
      } | ft -auto

      Where I must put your suggest?

      tks.

    • #83477

      Sergey Vasin
      Participant

      You should put it before "ft -auto".

  • #83483

    Pradeep Arora
    Participant

    If you were reading it from a file, you could use import-csv:

    $filename = ".\SignaldBm.txt"
    $alllines = Import-Csv $filename -Delimiter ' '  | where SinaldBm -le 25
    $alllines
    
    • #83510

      Rodrigo
      Participant

      Thanks for your reply,

      Actually, the script run a snmpwalk to a equipment. I need to show, after put the data in a table(s) only value minor that -25...or another after parametrization.

  • #83528

    Alex Aymonier
    Participant

    Rules to remember in PowerShell. Filter as far to the left as possible and format to the right. Once you format your data you are done.

  • #83594

    Rodrigo
    Participant

    Hi all,

    With Where don't work. I tried with IF command but don't work too.

    Below all script:

    $target = @()
    $ini| foreach {
        
        $strnum = (snmpwalk.exe -Ln -On -v 2c -c public $hostip ".1.3.6.1.4.1.3709.3.6.2.1.1.22")
        
        $strnum.Count
        $strcli = $strnum
    
    
        ##Remove String Chars from Uptime###
        $strNum = $strnum.Substring(51,3)
        $strcli = $strcli.Substring(31,9)
        
       
     
    }
       
       $strnum
       $strcli
        
        #write-host "Total Clientes:$($strnum.count)Clientes Limite: $($strnum |sort)"
      
    $column1 = @($strnum)
    $column2 = @($strcli)
    
    $i=0
    ($column1,$column2 | sort length)[1]|
    foreach {
      new-object psobject -property @{
                                        Sinal = $Column1[$i]
    
                                        Cliente = $column2[$i++]
                                       
                                       }
       
                                       
       
        
        where $column1[$i] -le -28
      }  | ft -AutoSize
    
      
  • #83833

    Rodrigo
    Participant

    Hi people,

    My script don't work yet. Someone has an idea how I could do this?

    Have another doubt: How I get the value of the first column? EX:
    POP1 -25
    POP2 -27
    POP3 -25
    POP4 -28
    POP5 -24
    POP6 -23
    POP7 -24
    POP8 -23

    I need get this: POP4 -28

    Thank you.

    rc.

  • #83836

    Rodrigo
    Participant

    Remember: POP4 is in a array, -28 is in another one.

  • #83851

    Curtis Smith
    Participant

    Hey Rodrigo,
    Like Sergey said, it should be before the ft -auto

    Currently you have:

      }  | ft -AutoSize

    It would go:

      }  | ‹here› | ft -AutoSize
  • #83923

    Rodrigo
    Participant

    Hi people,

    Thank you so much for the all help! Now, the code is working. Is possible to remove the first line of the result?

    Result of script:
    Sinal Cliente
    —– ——-
    -18 16777472
    -20 16777728
    -19 16777984
    -19 16778240
    0.0 16778496
    -19 16778752
    -24 16779008
    -17 16779264
    -19 16779520
    -22 16779776
    0.0 16780032
    -18 16780288
    -19 16780544
    -19 16780800
    -21 16781056
    -25 16781568
    -19 16781824
    -22 16782080
    -21 16782336
    -21 16782592
    -22 16783104
    -22 16783360
    -22 16783616
    -22 16783872
    -24 16784128
    -24 16784384
    0.0 16784640
    0.0 16784896
    -22 16785152
    -23 16785408
    -21 16785664
    -25 16785920
    -22 16786176
    -24 16786432
    0.0 16786688
    -25 16786944
    -30 16787200
    -22 16787456
    -24 16787712
    -25 16787968
    0.0 16788224
    -22 16788480
    -24 16788736
    -24 16788992
    -22 16789248
    -21 16789504
    -24 16789760
    -26 16789762
    -22 16790016
    0.0 16790272
    -22 16790528
    -23 16790784
    -22 16791040
    -22 16791296
    -21 16791552
    0.0 16791808

    Result After applied the filter
    Sinal Cliente
    —– ——-
    -25 16781568
    -25 16785920
    -25 16786944
    -30 16787200
    -25 16787968
    -26 16789762

    Result expected for my monitoring system
    -25 16781568
    -25 16785920
    -25 16786944
    -30 16787200
    -25 16787968
    -26 16789762

  • #83929

    Ron
    Participant

    Instead of

    | ft -AutoSize

    Use

    | %{write-output "$($_.Sinal) $($_.Cliente)"}
  • #83936

    Rodrigo
    Participant

    Thank you all! The script works fine!!!

    rc.

You must be logged in to reply to this topic.