# encoding: ascii
# api: powershell
# title: Execute-SQLCommand
# description: Simple function that executes a command (stored procedure) against an SQL database.
# version: 0.1
# type: function
# author: dragonmc77
# license: CC0
# function: Execute-SQLCommand
# x-poshcode-id: 480
# x-derived-from-id: 481
# x-archived: 2016-10-13T05:23:24
# x-published: 2008-07-24T09:18:00
#
#
function Execute-SQLCommand {param( [string]$Server, #the host name of the SQL server
[string]$Database, #the name of the database
[System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;User ID=ml;Initial Catalog=$Database;Data Source=$Server"
$Command.CommandType = 1 # 1 is the 'Text' command type
$Command.Connection = $sqlConnection
$sqlConnection.Open()
$Result = $Command.ExecuteNonQuery()
$sqlConnection.Close()
if ($Result -gt 0) {return $TRUE} else {return $FALSE}
}