SQLPart 2.of 3
This sample PowerShell code get you connected to a SQL Server and run a SQL command "Delete..." using the ".
ExecuteNonQuery". This is all .NET Framework working for you.
Executing a SQL Command
|
## - SQL Database information
## - Prepare queries to be executed
$SqlServer = "YourServerName";
$SqlCatalog = "YourDatabase";
## Creating a Connection
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
$SqlConnection.ConnectionString = "Server = '$SqlServer'; Database = '$SqlCatalog'; " `
+ "Integrated Security = True; Connect TimeOut=300";
$SqlConnection.Open();
## Use only clear the table
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
$SqlCmd.Connection = $SqlConnection;
$SqlCmd.CommandTimeout = 200;
$SqlCmd.CommandText = "Delete from tblSysLogs;";
$SqlCmd.ExecuteNonQuery();
$SqlCmd.Connection.Close();
|
I will post more sample reading a table this week.
Check out the last part 3 of 3 of the series next...