Skip to content

Instantly share code, notes, and snippets.

@nivleshc
Created June 7, 2017 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivleshc/757b758de4b13091ef29cf9c2ba0843b to your computer and use it in GitHub Desktop.
Save nivleshc/757b758de4b13091ef29cf9c2ba0843b to your computer and use it in GitHub Desktop.
A simple script to shutdown servers
<#
This script will shutdown all servers that are in the @serverlist and are active
Changelog
Date Author Comments
02/06/17 Nivlesh Initial version
#>
$serverlist = @("Server01","Server02","Server03","Server04","Server05")
$server_domainname = "domain.local"
foreach ($server in $serverlist){
$server_fqdn = -join ($server, ".", $server_domainname)
Write-Host "[$server_fqdn]" -NoNewline
if (Test-Connection -ComputerName $server_fqdn -Count 1 -ErrorAction SilentlyContinue){
Write-Host -ForegroundCOlor Green "Online. Initiating Shutdown" -NoNewline
Stop-Computer -ComputerName $server_fqdn -force
Write-Host -ForegroundColor Green " ServerShutdownSuccessfully"
}else{
Write-Host -ForegroundColor Red "Server is Offline"
}
}
Read-Host -Prompt "Press Enter when ready to shutdown this host or CTRL+C to Skip"
Stop-Computer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment