Powershell script to ping a server and try multiple domains: Difference between revisions

From roonics
Jump to navigation Jump to search
(Created page with "stuff")
 
No edit summary
Line 1: Line 1:
stuff
So this script will ping a server/computer and cycle through some domains to help identify which domain the server/computer is on.
 
Script:
<pre>
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 DOWN" -ForegroundColor Red
  }
}
</pre>
 
Useage:
<pre>.\domain.ps1 servername</pre>
 
Example output:
 
Example output:
<pre style="color: white; background: #012456; width: 800px">
server01.testdomain.com
server01.stagingdomain.com UP
server01.productiondomain.com
</pre>

Revision as of 14:43, 9 September 2021

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 DOWN" -ForegroundColor Red
  }
}

Useage:

.\domain.ps1 servername

Example output:

Example output:

server01.testdomain.com
server01.stagingdomain.com UP
server01.productiondomain.com