Powershell 2.0 and Sql server 2005 help

I am trying to figure out a way using either powershell or command line to confirm that as data base is online after I started the Database service?

I find some commands out there but they don’t seem to do what I need to do. I have very limited SQL experience.

It all depends on how you want to Connect etc. But this is an outline of how you could do it:

$connectionString = "connectionstring" 
#open database connection to SQL Server

$conn = New-Object system.Data.SqlClient.SqlConnection
$conn.connectionstring = $connectionString
$conn.open()

switch ($conn.State)
{

  "Open" {  Write-OutPut "Do some work"; }

  Default { Write-OutPut "The connection is $($conn.State).  There has been an error connecting to the database."; }
}


Thank you very much Joakim. I will try this and report back.