none
Need help with powershell write-progress cmdlet. RRS feed

  • Question

  • Hi,

    I have the following script scanning the LAN for ip addresses and sending the result to a csv file

     

    1..254 | foreach { New-Object psobject -prop @{Address="192.168.59.$_";Ping=(Test-Connection "192.168.59.$_" -Quiet -Count 2)}} | Out-File D:\Tech\IpscanResult.csv

     

    I would like to know how I can add a progress bar while the scanning is in progress. I know we can use the write-progress cmdlet but I don’t know how to use it in this situation.

    Anyone?

    FrenchITGuy.com
    Friday, July 1, 2016 8:32 PM

Answers

  • Did you read the help?


    $range = 1..254
    $range | ForEach-Object {
      $address = "192.168.59.$_"
      Write-Progress "Pinging hosts" $address -PercentComplete (($_/$range.Count)*100)
      New-Object PSObject -Property @{
        Address = $address
        Ping = Test-Connection $address -Quiet -Count 2
      }
    }


    -- Bill Stewart [Bill_Stewart]

    Friday, July 1, 2016 8:47 PM
    Moderator

All replies

  • Did you read the help?


    $range = 1..254
    $range | ForEach-Object {
      $address = "192.168.59.$_"
      Write-Progress "Pinging hosts" $address -PercentComplete (($_/$range.Count)*100)
      New-Object PSObject -Property @{
        Address = $address
        Ping = Test-Connection $address -Quiet -Count 2
      }
    }


    -- Bill Stewart [Bill_Stewart]

    Friday, July 1, 2016 8:47 PM
    Moderator
  • Thank You. It works like a charm!

    FrenchITGuy.com

    Friday, July 1, 2016 9:01 PM
  • Hi, Please try below as well and check your output.

    $range = 1..254
    $range | ForEach-Object {
      $address = "192.168.59.$_"
      Write-Progress "Pinging hosts" $address -PercentComplete (($_/$range.Count)*100)
      New-Object PSObject -Property @{
        Address = $address
        Ping = Test-Connection $address -Quiet -Count 2 -errorAction silentlyContinue
      }
    } | select Address, Ping | Export-csv D:\Tech\IpscanResult.csv -append

    Regards

    Kam

    Friday, July 1, 2016 9:57 PM
  • What's the point of reposting code I already posted?

    -- Bill Stewart [Bill_Stewart]

    Friday, July 1, 2016 9:59 PM
    Moderator