Perrypackettracer / Powershell-scripts-to-use-in-an-active-directory

0 stars 0 forks source link

Powershell script to ping other servers in a loop to see availability #18

Open Perrypackettracer opened 8 months ago

Perrypackettracer commented 8 months ago

Below is a PowerShell script that automates network-related tasks by checking the availability of multiple servers using ping. You can modify this script according to your specific needs, such as configuring network settings or performing other network-related tasks.

# Define a list of servers to ping
$Servers = @("server1", "server2", "server3")

# Define a timeout value for the ping command (in milliseconds)
$Timeout = 1000

# Loop through each server and check connectivity
foreach ($Server in $Servers) {
    $PingResult = Test-Connection -ComputerName $Server -Count 2 -TimeoutMillis $Timeout -ErrorAction SilentlyContinue

    if ($PingResult) {
        Write-Host "$Server is reachable. Response Time: $($PingResult.ResponseTime) ms"
    } else {
        Write-Host "$Server is unreachable."
    }
}

Explanation:

  1. Modify the $Servers array with the list of server names or IP addresses you want to check.

  2. Set the $Timeout variable to specify the maximum time (in milliseconds) to wait for a ping response.

  3. The script uses Test-Connection to ping each server in the list.

  4. It checks if the server is reachable and displays the response time if available.

  5. Customize the script based on your specific network-related tasks. For example, you can add additional commands to configure network settings, check DNS resolution, or perform other tasks.

  6. Execute the script to automate the network-related tasks. You can schedule it to run periodically using Task Scheduler or any other automation tool.

For software deployment and updates, PowerShell can also be used to install or update software on remote machines. This typically involves using commands like Invoke-Command to execute installation scripts on target servers. If you have specific requirements for software deployment or updates, please provide more details so I can tailor the script accordingly.