I have a script that has been running perfectly for five years. It scripts out database objects. Upon moving to a new server - from 2012 to 2016 - and from Powershell version 4 to version 5, it has begun to consume massive amounts of memory. This happens when it is scripting large numbers of tables or views. I am trying to convert the script from using the Foreach loop to using the Foreach-object.
The problem is that I cannot make the script statement work.
I can tell that with the foreach loop, $tbl returns a set of data and I can script it with this statement: $scrp.Script($tbl)
Schema Name Row Count Storage Index Created Space Used Space Used
dbo SomeTable 2508 152.00 KB 152.00 KB 4/2/2010 5:34 PM
With the foreach-object, I seem to need to specify each property I'll need later in my script:
$db.Tables | foreach-object {$tbl = $_.name; $scm =$_.Schema; $sys = $_.IsSystemObject; $crp = $_.IsEncrypted}...
$scrp.Script($tbl) no longer works because the $tbl variable only contains the name of the table. I've tried $scm + '.' + $tbl and that also doesn't work.
Can somebody tell me how to script out my tables?
Thanks in advance.
Judy