I'm missing something stupid, and can't figure it out

8 views
Skip to first unread message

Kurt Buff

unread,
Mar 29, 2023, 6:22:12 PM3/29/23
to ntpowe...@googlegroups.com
This should work - I've stared at it for over an hour. Actually, it does work - sort of. I've got 18 csv files in the directory (soon to be hundreds), each with data from which I want to calculate/extract the 95th percentile.

It does the first file just fine, but never proceeds to the rest of the files. I've checked for matches on parens and curly braces, and they look correct to me.

When I check the contents of $files, it shows the list as I expect. The output for the first file looks correct and I get no error messages.

What did I screw up this time?

----------begin script
$files = get-childitem c:\temp\pingstats\*.csv | select -expand fullname
foreach ( $file in $files ) {
   write-host $file
   $results = import-csv $file | select -expand responsetime -skip 1 | sort
   [int]$N = $results.Length
   write-host "N is $N"
   [Double]$Num = ($N - 1) * .95 + 1
   write-host "Num is $Num"
   if ($Num -eq 1) {
      return $results[0]
   } elseif ($Num -eq $N) {
      return $results[$N-1]
   } else {
      $k = [Math]::Floor($Num)
      write-host "k is $k"
      [Double]$d = $Num - $k
      write-host "d is $d"
      return $results[$k - 1] + $d * ($results[$k] - $results[$k - 1])
    }
}
----------end script
----------output
C:\temp\pingstats\Server1-Server2-pingstats.csv
N is 4974
Num is 4725.35
k is 4725
d is 0.349999999999454
700
----------output

Kurt

Michael B. Smith

unread,
Mar 29, 2023, 6:26:50 PM3/29/23
to ntpowe...@googlegroups.com

You “return” and leave the script.

 

Thanks.

 

Regards,

Michael B. Smith

Managing Consultant

Smith Consulting, LLC

--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntpowershell...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce5sKoL3EGnB%2Bsj2G%2BW__c1vJ9ZM2ssgQOzw55%2BjYAmehg%40mail.gmail.com.

Kurt Buff

unread,
Mar 29, 2023, 6:51:33 PM3/29/23
to ntpowe...@googlegroups.com
Ah.

That's what happens when you rep apart a function and don't know what you're doing.

Thanks,

Kurt

Reply all
Reply to author
Forward
0 new messages