Hopefully, this is not a duplicate. I aggregated numerous solutions I came across from the last year or so to get where I am. This is all relatively new to me and I am looking for the most secure and effective solution. When I run this, nothing happens. The intended result is to execute the stored procedure.
$Server = 'Server Name'
$database = 'DBName'
$userName = 'un'
$password = 'pw'
$Name = 'Name'
$Job = '15'
$Logs = Get-Content -Path $global:LOGFILE
$StartTime ='time'
$End = 'End'
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "Server=$('$Server');Database=$('$Database');trusted_connection=true;User Id=$('$userName');Password=$('$password')"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$Command.CommandText ="EXEC dbo.UpdateOutput @Name,@Job,@StartTime,@End,@Status,@Logs"
$Command.Parameters.AddWithValue("@Name", $Name)| Out-Null
$Command.Parameters.AddWithValue("@Job", $Job)| Out-Null
$Command.Parameters.AddWithValue("@Start", $StartTime)| Out-Null
$Command.Parameters.AddWithValue("@End", $End)| Out-Null
$Command.Parameters.AddWithValue("@Status", $Status)| Out-Null
$Command.Parameters.AddWithValue("@Logs", $Logs)| Out-Null
$Command.ExecuteNonQuery()
$Connection.Close()