IF you have not read the Connecting to SQL blog. I would recommand to read it first before start this.
Updating SQL tables using Powershell was quite fun doesn’t have to log into a SQL management server or any application its just you and Powershell like happy couple 😛
the below script will allow you to update a SQL table.
function Start-SQLUpdate
{
[CmdletBinding()]
param
(
[string]$Server,
[string]$Database,
[string]$SQLQuery,
[string]$ConnectionCredentials
)
$Datatable = New-Object System.Data.DataTable
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "server='$Server';database='$Database';$ConnectionCredentials"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$Command.CommandText = $SQLQuery
$UpdatedRecordCount = $Command.ExecuteNonQuery()
#return $UpdatedRecordCount
}
