I am having problems using Microsoft.SqlServer.Management.Smo.Table
objects with the Write-SqlTableData
cmdlet.
My code is similar to the following (names changed for privacy)
# $sc is a working SQL Server connection
$srv = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server $sc
$Table = $srv.databases["Database"].tables["Table"]
# $Data is a DataSet full of data
$Result = Write-SqlTableData -InputData $Data -InputObject $Table -PassThru
I am getting the following error:
Write-SqlTableData : Cannot bind parameter 'InputObject'. Cannot convert the "[dbo].[Table]" value of type "Microsoft.SqlServer.Management.Smo.Table" to type "Microsoft.SqlServer.Management.Smo.Table".
At C:\Script.ps1:177 char:68
+ ... ableData -InputData $Data -InputObject $Table -PassTh ...
+ ~~~~~~ + CategoryInfo : InvalidArgument: (:) [Write-SqlTableData], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.SqlServer.Management.PowerShell.WriteSqlTableData
All connections have been tested and working. I should have permission to access the database. I think that I may be missing something in terms of the creation of the table object. Maybe I need to give it more information in order to make that conversion. But it should be able to convert to an object of its own type right?