Exchangemaster GmbH company logo

Exchangemaster GmbH - A Swiss IT Consultancy
Services
References
Partners
Contact
Getting Started
FAQs
Presentations
Articles
Community
Search
Popular
Tell-a-Friend
Follow Me

Follow exchangemaster on Twitter

Who's Online
We have 64 guests online
Syndicate
FAQ 000134 - Use PowerShell to check if your servers are online PDF Print E-mail
User Rating: / 10
PoorBest 
Written by Dejan Foro   
Nov 21, 2014 at 02:25 AM

If you need  to quickly check if all of your servers are online, and you don't have a monitoring system implemented in your environment, you can use the following Powershell script.

It automatically generates a list of all servers based on information in Active Directory, checks connectivity to each of them and creates following output:

 

SERVER01 is ONLINE

SERVER02 is OFFLINE

SERVER03 is ONLINE

SERVER04 is ONLINE

 

 

<#
.NAME
   AreMyServersOnline
.VERSION
   1.0
.DATE
   November 20, 2014
.AUTHOR
   Dejan Foro
  
 
   Exchangemaster GmbH 
  
www.exchangemaster.ch

.SYNOPSIS
   Are my severs online?
.DESCRIPTION
   If you don't have a proper monitoring system in your environment, this script will help you to quickly check
   if your servers are offline or online. It gets a list of all servers in the current domain from Active
   Directory, checks each of them with a single ping and generates a color coded status list.
#>


#Clear the screen
cls


#Check if PowerShell module for Active Directory is available on the machine
Write-Host
Write-Host "Checking if PowerShell module for Active Directory is available on this machine..."
$ADModuleAvailable = $null
$ADModuleAvailable = Get-Module -ListAvailable | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleAvailable -eq $null){
  Write-Host -ForegroundColor Red "PowerShell module for Active Directory is not available on this machine."
  Write-Host -ForegroundColor Red "Please run this script on a domain controller or on a machine that has Active Directory management tools installed."
  Write-Host
  Exit}
 else{
  Write-Host -ForegroundColor Green "PowerShell module for Active Directory is availble."}
Write-Host


#check if Active Directory module is loaded
Write-Host "Checking if PowerShell module for Active Directory is already loaded..."
$ADModuleLoaded = $null
$ADModuleLoaded = Get-Module | where {$_.Name -eq "ActiveDirectory"}
if ($ADModuleLoaded -eq $null){
  Write-Host "Loading PowerShell module for Active Directory ..."
  Import-Module -Name "ActiveDirectory"}
Write-Host -ForegroundColor Green "Powershell module for Active Directory is loaded."
Write-Host


#Generate a list of all servers in the domain.
$ServerList = $null
$ServerList = Get-ADComputer -Filter 'OperatingSystem -like "*Server*"' -Properties Name | Select-Object Name | Sort-Object Name


#Check for each server in the list if server is online.
$IsOnline = $null
ForEach ($Server in $ServerList) {
 $IsOnline = Test-Connection -ComputerName $Server.Name -BufferSize 16 -Count 1 -Quiet
  if ($IsOnline -eq $true){
   Write-Host -ForegroundColor Green $Server.Name "is ONLINE"
   }
  else {
   Write-Host -ForegroundColor Red $Server.Name "is OFFLINE"
    }
    }

Last Updated ( Nov 21, 2014 at 06:30 PM )
<Previous   Next>