Created
June 7, 2017 02:13
-
-
Save nivleshc/757b758de4b13091ef29cf9c2ba0843b to your computer and use it in GitHub Desktop.
A simple script to shutdown servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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