Search This Blog

Tuesday, November 13, 2018

Run TimeStamped Pings against large Computer list

Had to run long term ping test against a number of devices. As such I created the following script that will ping the devices, with a timestamp, logging to a file.

computer list is in a file, should be in the same folder as the script. In this case file called ips.txt.

param ([ Int32 ] $ PingCount = 14400 , [ string ] $ file = '.\ips.txt' )

 

function Get-ScriptDirectory

{

    #Determine the folder in which the script lives.

    $ Invocation = ( Get-Variable MyInvocation -Scope 1 ).Value

    Split-Path $ Invocation .MyCommand.Path

}

 

$ scriptPath = Get-ScriptDirectory

 

$ TimeStampPing = {

    param ( $ comp , $ count , $ scriptPathBlock )

    filter timestamp { " $ ( Get-Date - Format o): $ _ " } ;

    ping $ comp -n $ count | timestamp > " $ ( $ scriptPathBlock )\pingtest- $ ( $ comp ).txt"

  }

 

foreach ( $ line in Get-Content $ file ) {

    Start-Job -ScriptBlock $ TimeStampPing -ArgumentList $ line , $ PingCount , $ scriptPath

}


Share/Bookmark

No comments:

Post a Comment