Skip to content

Instantly share code, notes, and snippets.

@SergeyAxenov
Last active August 29, 2015 14:20
Show Gist options
  • Save SergeyAxenov/e7be3068ffeca446fc81 to your computer and use it in GitHub Desktop.
Save SergeyAxenov/e7be3068ffeca446fc81 to your computer and use it in GitHub Desktop.
PowerShell check whether SQL server is online using SMO
# #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