bibi92
asked on
problem with loop
Hello,
I try to generate the script for a list of tables :
At D:\DBA\Script.ps1:112 char:25
+ $scrp.Script <<<< ($t)
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE xception
+ FullyQualifiedErrorId : MethodCountCouldNotFindBes t
Thanks
Regards
I try to generate the script for a list of tables :
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$s = new-object ('Microsoft.SqlServer.Management.Smo.Server') "$SRV-TEST"
$db=$s.Databases["$Database"]
$directory="d:\test"
if ($OBJET -eq "TABLE") {
$liste_source_table = (& sqlcmd -E -S "SRV-TEST" -h -1 -d VPDBA -b -W -Q "set nocount on;select distinct dest_db + '|' + new_dest_db + '|' + source_table from [DBA].[dbo].[ddl_configuration] where new_dest_db <> 'NULL' and new_dest_db <> ''")
foreach ($source_table in $liste_source_table) {
$array_str = $source_table.Split("|")
$dest_db = $array_str[0].Trim()
echo $dest_db
$new_dest_db = $array_str[1].Trim()
echo $new_dest_db
$sc_table = $array_str[2].Trim()
echo $sc_table
echo "$dest_db.$source_table"
$scrp = new-object ('Microsoft.SqlServer.Management.Smo.Scripter') ($SQLSERVER_SPOT)
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $s.Databases.Item($dest_db)
$scrp.Options.DriPrimaryKey=$true
$scrp.Options.AppendToFile = $true
$scrp.Options.FileName = $DIRECTORY + "\" + "SPOT.$($new_dest_db).Create.Tables.sql"
echo $scrp.Options.FileName
$tbl = $db.tables | where-object { $_.name -eq $t}
echo $t
foreach ($t in $tbl) {
$scrp.Script($t)
}
}
}
Multiple ambiguous overloads found for "Script" and the argument count: "1".At D:\DBA\Script.ps1:112 char:25
+ $scrp.Script <<<< ($t)
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE
+ FullyQualifiedErrorId : MethodCountCouldNotFindBes
Thanks
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Dan