Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

problem with loop

Hello,

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)

  }
 }
}

Open in new window

Multiple ambiguous overloads found for "Script" and the argument count: "1".
At D:\DBA\Script.ps1:112 char:25
+             $scrp.Script <<<< ($t)
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Thanks

Regards
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

The error is apparently occurring at line 112 at character 25.  I'll guess you only posted a snippet of your script.  Which line is 112 in your script?

Dan
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

Thanks