SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
How To Check Server Status - PowerShell
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To..................................................................................................................................................1
Pre-Requisites ...........................................................................................................................................1
PowerShell Script - Check Server’s Status.....................................................................................................1
Code Snippet.............................................................................................................................................1
PowerShell Output....................................................................................................................................3
Single Server – Output ..........................................................................................................................3
Multiple Servers – Output.....................................................................................................................3
How To Check Server Status - PowerShell
1 | P a g e
Overview
In this post / snippet we will demonstrate, check server status utilizing ping command result output and
writing the output to a “CSV” file.
This script will read the server name(s) in the file and check each server status and loop through and also
this script can be utilized to check one server, wherein server names list is not needed.
Applies To
Tested on Windows 10, Windows 2008 R2 and Windows 2012.
Pre-Requisites
Launch PowerShell Command Console or PowerShell ISE.
To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or
“Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”.
Policy Type Purpose
Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned Only scripts signed by a trusted publisher can be run.
RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted No restrictions; all Windows PowerShell scripts can be run.
 To check Multiple servers, ServersList.txt has to be created with list of servers that needs to be
checked.
 ServersList.txt file should contain, only one server name each line
 For Single Server, “ServersList.txt” is not necessary.
PowerShell Script - Check Server’s Status
This script will test servers listed in “ServersList.txt” file, wherein it will ping and if the server is alive it will
write output to CSV file “Host Name” and “Up / Down”.
Code Snippet
#
# Declare Variables
#
Clear-Host
$OutputFileName="c:tempServer_Status.csv"
#
# Delete Output file
#
if (Test-Path $OutputFileName ){
Clear-Host
Write-Host "Output File already Exists, deleting output file now - $OutputFileName.`n" -ForegroundColor Black -
BackgroundColor Green
Remove-Item $OutputFileName
How To Check Server Status - PowerShell
2 | P a g e
[console]::Beep(500,700)
}
#
# Validate to check Single or Muliple servers
#
$Check_Type=Read-Host "Do you want to Check status of (S)ingle or (M)ultiple Servers?"
if ($Check_Type -eq "S" -and $Check_Type -ne "") {
$ServerName=Read-host "Enter Computer Name"
if (Test-Connection -ComputerName $ServerName -Count 1 -ErrorAction SilentlyContinue) {
# Write Column Heading delimited by Tab
#
echo "Host Name`tNode Status" > $OutputFileName
#
# Write Node Up, delimited by tab
echo "$ServerName`tUp" >> $OutputFileName
} else {
# Write Column Heading delimited by Tab
#
echo "Host Name`tNode Status" > $OutputFileName
#
# Write Node Down, delimited by tab
echo "$ServerName`tDown" >> $OutputFileName
}
#
# Launch Ping Status Output File
#
Write-Host "Task completed, launching file"
Invoke-Item $OutputFileName
} elseif ($Check_Type -eq "m" -and $Check_Type -ne "") {
$ServersList="c:tempServersList.txt"
# Get Servers List
#
$ServerNames = Get-Content $ServersList
#
#
# Write Column Heading delimited by Tab
#
echo "Host Name`tNode Status" > $OutputFileName
#
# Loop Each Server and do ping test once
#
foreach ($ServerName in $ServerNames) {
$StartCount = 0
$TotalCount = (Get-Content $ServersList | Measure-Object | Select-Object -ExpandProperty Count)
#
# Test Node reachability (ping)
#
if (Test-Connection -ComputerName $ServerName -Count 1 -ErrorAction SilentlyContinue) {
# Write Node Up, delimited by tab
echo "$ServerName`tUp" >> $OutputFileName
} else {
# Write Node Down, delimited by tab
echo "$ServerName`tDown" >> $OutputFileName
}
$StartCount++
How To Check Server Status - PowerShell
3 | P a g e
#
# Progress Bar
#
Write-Progress -Activity "Collate Host Status" -Status "Pinging Hosts..." -PercentComplete ($StartCount / $TotalCount
*100)
}
#
# Launch Ping Status Output File
#
Write-Host "Task completed, launching file"
Invoke-Item $OutputFileName
} else {
Write-Host "Invalid Option`n" -BackgroundColor Red -ForegroundColor Green
[console]::Beep(600,700)
}
PowerShell Output
In this example we have defined 3 servers and hence the server check loop will run 3 times only.
Single Server – Output
To test single server, user has to key-in “Host IP / Hostname”.
Multiple Servers – Output
To test multiple servers, server’s to be tested are read from “ServersList.txt” file.
How To Check Server Status - PowerShell
4 | P a g e

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (17)

How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7
 
How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7
 
Install telnet Linux
Install telnet LinuxInstall telnet Linux
Install telnet Linux
 
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
 
LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7
 
How To Configure Apache VirtualHost on RHEL 7 on AWS
How To Configure Apache VirtualHost on RHEL 7 on AWSHow To Configure Apache VirtualHost on RHEL 7 on AWS
How To Configure Apache VirtualHost on RHEL 7 on AWS
 
How to Install Configure and Use sysstat utils on RHEL 7
How to Install Configure and Use sysstat utils on RHEL 7How to Install Configure and Use sysstat utils on RHEL 7
How to Install Configure and Use sysstat utils on RHEL 7
 
How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7
 
How To View Login History and Logout History on RHEL 7
How To View Login History and Logout History on RHEL 7How To View Login History and Logout History on RHEL 7
How To View Login History and Logout History on RHEL 7
 
Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7
 
Batch script for nslookup range of ip address
Batch script for nslookup range of ip addressBatch script for nslookup range of ip address
Batch script for nslookup range of ip address
 
Red Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with PuppetRed Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with Puppet
 
How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS Share
 
How To Find Package Installation Date on RHEL 7
How To Find Package Installation Date on RHEL 7How To Find Package Installation Date on RHEL 7
How To Find Package Installation Date on RHEL 7
 
How To Install and Use ABRT CLI on RHEL 7
How To Install and Use ABRT CLI on RHEL 7How To Install and Use ABRT CLI on RHEL 7
How To Install and Use ABRT CLI on RHEL 7
 
How To Check file exists and Delete PowerShell
How To Check file exists and Delete PowerShellHow To Check file exists and Delete PowerShell
How To Check file exists and Delete PowerShell
 
How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7
 

Mehr von VCP Muthukrishna

Mehr von VCP Muthukrishna (19)

How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7
 
How To Connect to Active Directory User Validation
How To Connect to Active Directory User ValidationHow To Connect to Active Directory User Validation
How To Connect to Active Directory User Validation
 
How To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShellHow To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShell
 
How To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShellHow To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShell
 
How To List Files and Display In HTML Format
How To List Files and Display In HTML FormatHow To List Files and Display In HTML Format
How To List Files and Display In HTML Format
 
How To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShellHow To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShell
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
 
How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7
 
How To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on UbuntuHow To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on Ubuntu
 
Windows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive InfoWindows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive Info
 
How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7
 
Windows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loopWindows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loop
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional Statements
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional ParameterHow To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter Value
 
How To Create PowerShell Function
How To Create PowerShell FunctionHow To Create PowerShell Function
How To Create PowerShell Function
 
How To Reset root Password on CentOS 7
How To Reset root Password on CentOS 7How To Reset root Password on CentOS 7
How To Reset root Password on CentOS 7
 
How To View Current Execution Policy PowerShell
How To View Current Execution Policy PowerShellHow To View Current Execution Policy PowerShell
How To View Current Execution Policy PowerShell
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

How to Check Server Status Windows PowerShell

  • 1. How To Check Server Status - PowerShell i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To..................................................................................................................................................1 Pre-Requisites ...........................................................................................................................................1 PowerShell Script - Check Server’s Status.....................................................................................................1 Code Snippet.............................................................................................................................................1 PowerShell Output....................................................................................................................................3 Single Server – Output ..........................................................................................................................3 Multiple Servers – Output.....................................................................................................................3
  • 2. How To Check Server Status - PowerShell 1 | P a g e Overview In this post / snippet we will demonstrate, check server status utilizing ping command result output and writing the output to a “CSV” file. This script will read the server name(s) in the file and check each server status and loop through and also this script can be utilized to check one server, wherein server names list is not needed. Applies To Tested on Windows 10, Windows 2008 R2 and Windows 2012. Pre-Requisites Launch PowerShell Command Console or PowerShell ISE. To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or “Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”. Policy Type Purpose Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned Only scripts signed by a trusted publisher can be run. RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run. Unrestricted No restrictions; all Windows PowerShell scripts can be run.  To check Multiple servers, ServersList.txt has to be created with list of servers that needs to be checked.  ServersList.txt file should contain, only one server name each line  For Single Server, “ServersList.txt” is not necessary. PowerShell Script - Check Server’s Status This script will test servers listed in “ServersList.txt” file, wherein it will ping and if the server is alive it will write output to CSV file “Host Name” and “Up / Down”. Code Snippet # # Declare Variables # Clear-Host $OutputFileName="c:tempServer_Status.csv" # # Delete Output file # if (Test-Path $OutputFileName ){ Clear-Host Write-Host "Output File already Exists, deleting output file now - $OutputFileName.`n" -ForegroundColor Black - BackgroundColor Green Remove-Item $OutputFileName
  • 3. How To Check Server Status - PowerShell 2 | P a g e [console]::Beep(500,700) } # # Validate to check Single or Muliple servers # $Check_Type=Read-Host "Do you want to Check status of (S)ingle or (M)ultiple Servers?" if ($Check_Type -eq "S" -and $Check_Type -ne "") { $ServerName=Read-host "Enter Computer Name" if (Test-Connection -ComputerName $ServerName -Count 1 -ErrorAction SilentlyContinue) { # Write Column Heading delimited by Tab # echo "Host Name`tNode Status" > $OutputFileName # # Write Node Up, delimited by tab echo "$ServerName`tUp" >> $OutputFileName } else { # Write Column Heading delimited by Tab # echo "Host Name`tNode Status" > $OutputFileName # # Write Node Down, delimited by tab echo "$ServerName`tDown" >> $OutputFileName } # # Launch Ping Status Output File # Write-Host "Task completed, launching file" Invoke-Item $OutputFileName } elseif ($Check_Type -eq "m" -and $Check_Type -ne "") { $ServersList="c:tempServersList.txt" # Get Servers List # $ServerNames = Get-Content $ServersList # # # Write Column Heading delimited by Tab # echo "Host Name`tNode Status" > $OutputFileName # # Loop Each Server and do ping test once # foreach ($ServerName in $ServerNames) { $StartCount = 0 $TotalCount = (Get-Content $ServersList | Measure-Object | Select-Object -ExpandProperty Count) # # Test Node reachability (ping) # if (Test-Connection -ComputerName $ServerName -Count 1 -ErrorAction SilentlyContinue) { # Write Node Up, delimited by tab echo "$ServerName`tUp" >> $OutputFileName } else { # Write Node Down, delimited by tab echo "$ServerName`tDown" >> $OutputFileName } $StartCount++
  • 4. How To Check Server Status - PowerShell 3 | P a g e # # Progress Bar # Write-Progress -Activity "Collate Host Status" -Status "Pinging Hosts..." -PercentComplete ($StartCount / $TotalCount *100) } # # Launch Ping Status Output File # Write-Host "Task completed, launching file" Invoke-Item $OutputFileName } else { Write-Host "Invalid Option`n" -BackgroundColor Red -ForegroundColor Green [console]::Beep(600,700) } PowerShell Output In this example we have defined 3 servers and hence the server check loop will run 3 times only. Single Server – Output To test single server, user has to key-in “Host IP / Hostname”. Multiple Servers – Output To test multiple servers, server’s to be tested are read from “ServersList.txt” file.
  • 5. How To Check Server Status - PowerShell 4 | P a g e