I have the following code below, I am trying to write the data to a table, but it keeps throwing up the following error. As you can see, I've tried several ways. I just can't find the issue.. Thank you for your help
At C:\Scripts\Sharepoint\LastUserLogon\ParseFile.ps1:111 char:1
+ $Cmd.ExecuteNonQuery();
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
Foreach ($item in $tbl_2)
{
$OU = $item.OU
$Type = $item.type -replace " ", ""
If ($OU -like "*$OU")
{
Write-Host $sam $OU $itemType $Date $OU
$csv = @"
"$sam",$Type","$LastLogon","$Enabled","$DN","$OU"
"@
$csv >>$ParseOutcsv
#$Cmd.CommandText = "INSERT INTO $tbl_3 (sam,Type,Enabled,Date,DN,OU) VALUES ('$sam','$Type','$lastLogon','$Enabled','$DN','$OU')"
#$cmd.ExecuteNonQuery()
$Cmd.Parameters.Add("@sam", $sam);
$Cmd.Parameters.Add("@Type", $Type);
$Cmd.Parameters.Add("@lastLogon", $lastLogon);
$Cmd.Parameters.Add("@Enabled", $Enabled);
$Cmd.Parameters.Add("@DN", $DN);
$Cmd.Parameters.Add("@OU", $OU);
$Cmd.CommandText = "INSERT INTO $tbl_3 (Sam,Type,Enabled,Date,DN,OU) VALUES (@sam,@Type,@lastLogon,@Enabled,@DN,@OU)";
$Cmd.ExecuteNonQuery();
}