Pages

Wednesday, August 12, 2020

ping multiple ip addresses from windows PowerShell script cmd

### save iplist in a txt file as "iplist.txt"

### save the script as "PingIP.ps1" ( powershell script )

### rightclick and choose "Run with PowerShell"


$names=Get-content "D:\tasks\Ping\iplist.txt"

foreach($name in $names){

if(Test-Connection -ComputerName $name -Count 2 -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 "D:\tasks\Ping\result.txt"

Start-Sleep -s 30



### iplist.txt ( without tab or space at end of line)

172.21.80.3

172.21.80.4

172.21.80.60

172.21.80.61

172.21.11.115

172.21.11.43

172.21.30.5

localhost



### result.txt ( looks like below )

172.21.80.3 is up,
172.21.80.4 is up,
172.21.80.60 is --------> down,
172.21.80.61 is up,
172.21.11.115 is up,
172.21.11.43 is up,
172.21.30.5 is up,
localhost is up,

Wednesday, June 6, 2018

sample waiting script, waits for 60 minutes and fails after that.


sample script


okFile=okay.ok
bFlagFound=false
waitCounter=0

while [ "$bFlagFound" = "false" ]; do
        if [ -e $okFile ]; then
                bFlagFound=true
        else
                sleep 60
                waitCounter=$(($waitCounter + 1))
                if [ $waitCounter -gt 60 ]; then
                        echo "$okFile flag not found, after waiting 60 minutes"
                        exit 1
                fi
        fi
done




echo "task 1"
echo "task 2"