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