I have a PowerShell script that reads in a date from a registry, then uses it in an SQL query
# get date from registry
$avdate = (readregistry -regpath "HKLM:\SOFTWARE\MCAFEE\agent" -targetval "InstallTime") -as [DateTime]
$avdate = $avdate.tostring("yyyy-MM-dd HH:mm:ss")
# query, ExecQuery() makes calls to the database, EscapeQuote() is for string formatting
$returnRS = ExecQuery("exec SystemCheckerVBS_UpdateComputer '" + (EscapeQuote($serialNumber)) + "','" + (EscapeQuote($computerName)) + "',3,'$hostip','$hostmac','$avdate','$ostype','$osbit','$spver','$sdc'")
#query function
function local:ExecQuery($sqlStr){
#write-host "query: $sqlstr" #debug
$SqlCmd.CommandText = $sqlStr
$SqlAdapter.SelectCommand = $SqlCmd
$dataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
return $dataSet
}
when running the query it produces (Exception calling "Fill" with "1" argument(s): "Error converting data type varchar to datetime."). using the "yyyMMdd" format also does not work, neither does passing it directly as a datetime object. here is where the SQL procedure receives the data, only other uses in procedure are being passed into insert and update statements without alteration. no other variables are or deal with datetime.
@I_AntiVirusDate datetime = '2001-01-01 00:00:01'
is this a formatting issue, syntax, or possibly something else?