简体   繁体   中英

check ping for multiple servers - powershell

how to check variables in each line of the text area and test them for ping

foreach ($textbox1 in $textbox1) {

    if (test-Connection -ComputerName $textbox1 -Count 2 -Quiet)
    {
        $path = "$([Environment]::GetFolderPath("Desktop"))\ping.txt";
        "$textbox1 is Pinging " | fl > $path; notepad $path;

    }
    else
    {
        $path = "$([Environment]::GetFolderPath("Desktop"))\notping.txt";
        "$textbox1 not pinging" | fl > $path; notepad $path;

    }
}

I want to check for each variable in text area individually and check them each whether it pings or not

Based on your comment, I will use an example of getting the content from a text file:

$Servers = gc "(path to txt file, 1 server per line)"

foreach($Server in $Servers){
    if (Test-Connection -ComputerName $Server -Count 2 -Quiet) {    
        Write-Host "$Server is Pinging "    
    } else {
        Write-Host "$Server not pinging"    
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM