listing all the Databases from a SQL Server from PowerShell
I was reading this thread http://web2.minasi.com/forum/topic.asp?TOPIC_ID=25963 , that discusses retrieving a list of databases from SQL server and a query was used.
There is also a Stored procedure available in SQL server to list all the databases, as I needed this before I had this code handy,
$Server = 'W2008'
$sqlCon = New-Object Data.SqlClient.SqlConnection
$sqlCon.ConnectionString = "Data Source=$server;Integrated Security=True"
$sqlCon.open()
$sqlCmd = New-Object Data.SqlClient.SqlCommand
$sqlCmd.Connection = $sqlCon
$sqlCmd.CommandType = 'StoredProcedure'
$sqlCmd.CommandText = 'sp_databases'
$sqlCmd.ExecuteReader() |% {$_.GetString(0)}
To list SQL servers I made a post about that before PowerShell get-SqlServerList
Enjoy,
Greetings /\/\o\/\/