SQL Server Services and cluster info along with last reboot time of Server
The below powershell script provide the information of when the server was last rebooted and the status of SQL Server Services and Cluster resources if the sql server is clustered environment.
clear
$servernames="C:\ServerList\ServerList.txt"
Get-Content $servernames|
ForEach-Object {
$ComputerName=$_
$S=Get-WmiObject `
-Class Win32_SystemServices
`
-ComputerName $ComputerName
IF ($S|Select PartComponent |
Where-Object {$_
-like "*ClusSvc*"})
{
Write-OutPut "$ComputerName is
clustered"
Invoke-command `
-ComputerName $ComputerName
`
-ScriptBlock{
Get-WmiObject Win32_operatingsystem|
Select-Object CSName,@{Label='LastBootTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}
Invoke-Command `
-ComputerName $ComputerName
`
-ScriptBlock{
Get-Service -Name "*sql*"
}|Format-Table -AutoSize
Invoke-Command `
-ComputerName $ComputerName
`
-ScriptBlock{
Get-ClusterResource
}|Select-Object Name,State,ResourceType,PSComputerName|Format-Table -AutoSize
}
else #If a
server is not clustered then all the services should be up and running.
{
Write-OutPut "$ComputerName is not
clustered"
#This provides last uptime
Invoke-command `
-ComputerName $ComputerName
`
-ScriptBlock{
Get-WmiObject Win32_operatingsystem|
Select-Object CSName,@{Label='LastBootTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}
Invoke-Command `
-ComputerName $ComputerName
`
-ScriptBlock{
Get-Service -Name "*sql*"
}|Format-Table -AutoSize
}
}
#|Out-File "C:\ServerList\Results.txt"
Comments