PingAsync with Progress bar

Welcome Forums General PowerShell Q&A PingAsync with Progress bar

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
2 months, 4 weeks ago.

  • Author
    Posts
  • #166540

    Participant
    Topics: 10
    Replies: 9
    Points: 30
    Rank: Member

    Is there a way to get progress bar of just a certain about of computers that have a successful ping? In the example below, if I had 1500 computers to ping, I would only want to keep pinging computers if I did not get 100 successful pings. Is that possible? Thanks.

    $ComputerList='computer1','computer2','computer3'...'computer 1500'
    
    $ComputerList | ForEach-Object -Process {
        $PingAsyncList+=(New-Object System.Net.NetworkInformation.Ping).SendPingAsync($_)
    }
    
  • #166600

    Participant
    Topics: 2
    Replies: 1000
    Points: 1,951
    Helping Hand
    Rank: Community Hero

    You can't do what you are after with just what you have.

    You need to have conditional code to check for that.

    You also, Don't want to make this endless/infinite loop check. Thus, look at using a DoWhile for the criteria you are after and exit after a certain number of tries.

    Personally, I am not really sure why you want to do it this way. Either the machine responds or it does not, and move on. Sure, you could have a machine have a response hiccup, but just report that and move on.

    You could do the later and try the list again, after the main effort completes.

    Also, what you are using is not going to return what you say you are after.

    Why are you using the .Net name space vs using the built-in cmdlets...

    Test-Connection -ComputerName
    Test-NetConnection -ComputerName

    And just taking action on the success response.  Yes, you can use those in an async fashion as well.

    Lastly, there are lots of examples of using PowerShell as a ping sweeper, all over the web. Just search for them.

    Example (s):

    'powershell ping fast'

    https://gallery.technet.microsoft.com/scriptcenter/Fast-asynchronous-ping-IP-d0a5cf0e

    https://gallery.technet.microsoft.com/scriptcenter/Most-faster-ping-of-a2e26929

    https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/final-super-fast-ping-command

    http://ramblingcookiemonster.github.io/Invoke-Ping

    As far as the progress bar part. Look to the...

     # get function / cmdlet details
    Get-Command -Name Write-Progress -Syntax
    (Get-Command -Name Get-ADUser).Parameters.Keys
    Get-help -Name Write-Progress -Full
    Get-help -Name Write-Progress -Online
    Get-help -Name Write-Progress -Examples

    … cmdlet help file for usage details, or use one of the models via the MS powershellgallery.com resources.

    Find-Module -Name '*progress*' | Format-Table -AutoSize
    
    Version Name             Repository Description                                                                                                             
    ------- ----             ---------- -----------                                                                                                             
    0.132   PoshProgressBar  PSGallery  A module for creating WPF progress bars using XAML and the Material Design Toolkit by Butchers Boy                      
    1.1     psInlineProgress PSGallery  Inline Progress Bar for PowerShell                                                                                      
    0.21    write-ProgressEx PSGallery  Write-ProgressEx extends the functionality of the standard cmdlet. Write-ProgressEx is a powershell advanced function...

     

     

     

     

     

     

You must be logged in to reply to this topic.