Diniz Martins

Nov 5, 20211 min

PowerShell ISE | Multiple Ping

The Windows PowerShell Integrated Scripting Environment (ISE) is a graphical user interface and front-end hosting application for Windows PowerShell. The ISE enables developers to run PowerShell commands and create, test and refine PowerShell scripts without the need to operate directly in the traditional PowerShell command-line interface (CLI).

At first glance, PowerShell ISE is a convenient GUI for the PowerShell console. The ISE provides a variety of editing controls, user help and other ease-of-use features that aren't readily present in PowerShell. For example, the ISE supports multi-line editing, tab completion, syntax-based coloring, selective execution, context-sensitive help and multi-language support. Menu options and keyboard shortcuts in the ISE mimic many of the common tasks traditionally performed in the PowerShell console.

Advantages of PowerShell ISE:

- Time savings and reduced errors in script creation;

- Improved debugging and testing;

- Greater insight into related scripts, ...

Disadvantages of PowerShell ISE:

- Unnecessary complexity for certain tasks;

- Limited paging;

- Lack of support for certain legacy commands, ...

This is a small utility that allows you to easily ping multiple host names and IP addresses, and export the result in one file.

First of all, you need to create hosts.txt and enter all the IP addresses you need to respond to and run the script below.

Code:

$name=Get-content "C:\tmp\hosts.txt"
 
foreach($name in $name)
 
{
 
if(Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
 
Write-Host "$name is up" -ForegroundColor Green
 
$output+="$name is up!"+"`n"
 
}
 
else{
 
Write-Host "$name is down" -ForegroundColor Red
 
$output+="$name is down!"+"`n" }
 
}
 
$output | Out-File "C:\tmp\result-hosts.txt"
 
Start-Sleep -s 15

The result:

192.168.0.1 is up!
 
192.168.0.2 is up!
 
192.168.0.3 is down!
 
192.168.0.4 is up!
 
192.168.0.5 is down!

In the Windows folder (C:\tmp) you will have a new file with the output result of the script.

    3560
    3