Powershell: connectie met SQLServer
Vrijdag 19 Juni 2009 at 09:51 am. Gebruikte Tags: ms_sql, powershell, sqlserverEen script om via PowershellDatabases op MS SQL Server aan te spreken.
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$DataSet = New-Object System.Data.DataSet
$SqlConnection.ConnectionString = "Server=eenserver;Database=eendatabase;User=eengebruiker;password=eengeheim;Integrated Security=True"
$SqlCmd.CommandText = "sp_databases"
$SqlCmd.Connection = $SqlConnection $SqlAdapter.SelectCommand = $SqlCmd
$SqlAdapter.Fill($DataSet)|out-null
$dbs =$DataSet.Tables[0] $dbs
$SqlConnection.Close()
Geen reacties