Hello all,
Having a problem inserting to MSSQL server Database.
Code:
$user = ([adsisearcher]“(&(objectClass=user)(samaccountname=$owner))”).FindOne().Properties
$samAccountname = $user.samaccountname
$UserPrincipalName = $user.userprincipalname
$DistinguishedName = $user.distinguishedname
$sqlCmd = $sqlConn.CreateCommand()
$sqlCmd.Parameters.AddWithValue("@user_login" ,$samAccountname)
$sqlCmd.Parameters.AddWithValue("@user_domain" ,$DOMAIN)
$sqlCmd.Parameters.AddWithValue("@distin_name" ,$DistinguishedName)
$sqlCmd.Parameters.AddWithValue("@update" ,$date)
$sqlCmd.Parameters.AddWithValue("@user_pincipal",$UserPrincipalName)
$sqlCmd.CommandText = "INSERT INTO [dbo].[USERS] ([USER_LOGIN],[USER_DOMAIN],[DISTIN_NAME],[UPDATE],[USER_PINCIPAL]) VALUES (@user_login,@user_domain,@distin_name,@update,@user_pincipal)";
$sqlCmd.ExecuteNonQuery(); #Here gives ERROR
$sqlCmd.Dispose;
The error it gives is :
Exception calling “ExecuteNonQuery” with “0” argument(s): “No mapping exists from object type System.DirectoryServices.ResultPropertyValueCollection to a known managed provider native type.”
At line:1 char:1
- $sqlCmd.ExecuteNonQuery();
-
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentException
Can anyone help me with this?
Regards