title: How do I sort a string by its numerical value in PowerShell
body: <p>I'm trying to create a script that will list the servers I need to list along with the latency returned from each server, I need the list to be in ascending or descending order based on ping.</p>
  
  <p>What I've come up with so far has given basically what I want, but if the ping returned is above 100 on one server, the other values are considered to be higher if they start with a value higher than 1.</p>
  
  <p>I understand that I need the ping value returned as an integer, but I haven't been able to figure out exactly how to accomplish that with out removing the server name.</p>
  
  <p>Anyway, here's what I've come up with so far</p>
  
  <pre><code>function TestNetwork {
      $global:array = @("&lt;ServerName&gt;:&lt;ipaddress&gt;"; "&lt;ServerName&gt;:&lt;ipaddress&gt;"; "&lt;ServerName&gt;:&lt;ipaddress&gt;")
  
      foreach ($str in $global:array) {
          $avg = 0
          $server = $($str -split ":")[0]
          $PingServer = Test-Connection -Count 3 $server
          $avg = ($PingServer | Measure-Object ResponseTime -Average)
          $calc = [System.Math]::Round($avg.Average)
          $output = "{000} | " -f $($calc) + $server
          $Output
      }
  }
  TestNetwork | Sort numerical -Descending `
  </code></pre>
  
  <p>and here are the results I get</p>
  
  <pre>
  75 | Server    
  73 | Server  
  110 | Server  
  </pre>