We managed 100 + servers and we want make sure they come back after monthly maintenance reboot. We will run the following script by confirming the servers are Up. I retrieve servername from a Table called SQLServers from Database - DBA_ServerDW from ServerInstance name SQLTEST.
$servername = invoke-sqlcmd -ServerInstance SQLTEST -Database DBA_ServerDW `
-Query "select ServerName from DBA_ServerDW.dbo.SQLServers
where servername not like '%\%'"
ForEach ($server in $servername)
{
# Ping the machine to see if it's on the network
$ServerN=$server.ServerName
$results = Get-WMIObject -query "select StatusCode from Win32_PingStatus where Address = '$ServerN'"
$responds = $false
ForEach($result in $results) {
# If the machine responds break out of the result loop and indicate success
if ($result.statuscode -eq 0) {
$responds = $true
break
}
}
If ($responds) {
# Gather info from the server because it responds
Write-Output "$ServerN responds"
} else {
# Let the user know we couldn't connect to the server
Write-Output "$ServerN does not respond"
}
}
Thank you for visiting my blog. My site is intended to share information and knowledge with others as well as a reference site for me.
Subscribe to:
Post Comments (Atom)
How to add a Database to AlwaysOn Availability Group with four different options
To add a database to an existing AlwaysOn availability group, MS has given us four options to choose from Automatic seeding Full database an...
-
When you use JDBC driver to set up an application connection string to MS SQL Server database, it passed the sendStringParametersAsUnicode p...
-
Recently, we have encountered Secondary replica was in Resolving State and took 3 minutes to take over primary role when we forced reboot pr...
-
NIC Provider Order Hello 2017! I hope everyone had a great 2016. My son was born in December 2016 and 2016 was the best year for me. No...
No comments:
Post a Comment