Powershell script to ping a server and try multiple domains: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 32: | Line 32: | ||
[[Category:PowerShell]] | [[Category:PowerShell]] | ||
<comments /> |
Latest revision as of 10:06, 20 March 2022
So this script will ping a server/computer and cycle through some domains to help identify which domain the server/computer is on.
Script:
param([string]$servername) $domains = @('testdomain.com', 'stagingdomain.com', 'productiondomain.com') foreach ($domain in $domains){ $finalcomputername = $servername + $domain if (Test-Connection -ComputerName $finalcomputername -Count 1 -ErrorAction SilentlyContinue){ Write-Host "$finalcomputername ** UP **" -ForegroundColor Green } else{ Write-Host "$finalcomputername" -ForegroundColor Red } }
Useage:
.\domain.ps1 servername
Example output:
server01.testdomain.com server01.stagingdomain.com ** UP ** server01.productiondomain.com
<comments />