Last active
August 29, 2015 14:20
-
-
Save SergeyAxenov/e7be3068ffeca446fc81 to your computer and use it in GitHub Desktop.
PowerShell check whether SQL server is online using SMO
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
# #powershell #ps #sql #smo #status #isOnline | |
Import-Module “sqlps” -DisableNameChecking | |
function SMO-IsServerOnline { | |
[CmdletBinding()] | |
[OutputType([boolean])] | |
Param( | |
[string]$serverName | |
) | |
$srv = new-object Microsoft.SqlServer.Management.Smo.Server($serverName) | |
$serverStatus = $srv.Status | |
return ($serverStatus -eq [Microsoft.SqlServer.Management.Smo.ServerStatus]::Online) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment