PoshCode Archive  Artifact [54b2cab0ef]

Artifact 54b2cab0efdb56133091f364048f89bdd23c3d413615496f0bd45414a9940489:

  • File Ping-t-using-powershell.ps1 — part of check-in [67971a105e] at 2018-06-10 13:59:12 on branch trunk — Ping -t with list of servers names (user: Krushna size: 1478)

# encoding: ascii
# api: powershell
# title: Ping -t using powershell
# description: Ping -t with list of servers names
# version: 0.1
# type: function
# author: Krushna
# license: CC0
# function: Get-FileName
# x-poshcode-id: 5682
# x-archived: 2015-01-18T22:42:04
# x-published: 2015-01-12T02:56:00
#
#
<#
 # Function to select any file using GUI from Powershell
 #Downloaded from technet
 http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/01/hey-scripting-guy-september-1.aspx
#>

Function Get-FileName($initialDirectory)
{  
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
 Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 return($OpenFileDialog.filename)
} #end function Get-FileName

# *** Entry Point to Script ***
$inpoutfilepath =   Get-FileName -initialDirectory "c:\"
if($inpoutfilepath -ne "")
{
    if (Test-Path $inpoutfilepath)  #"D:\servers.txt"
    {
         $ComputerNames=Get-Content $inpoutfilepath
    
         foreach ($ComputerName in $ComputerNames) 
         {
            start-process cmd  " /c ping $ComputerName -t"
          }
    }
    else
    {
        Write-Warning "unable to find the input file"
    } 
}
    else
    {
        Write-Warning "No File has been selected"
    }