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...
-
Tempdb filled up last night and databases availability group are not accessible in secondary replica. After restarting a secondary SQL insta...
-
After changing a service account running SQL server, I get an error when I connect to SQL server from Management Studio from my laptop or ot...
-
I was working on a powershell script which tells me which node is AlwaysOn primary replica. We have 38 servers which participate in AlwaysOn...
No comments:
Post a Comment