Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3239730
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:00:15+00:00 2026-05-17T18:00:15+00:00

I get this error message when I run the Powershell script at the bottom:

  • 0

I get this error message when I run the Powershell script at the bottom:

Exception calling "EnumScript" with "1" argument(s): "Script failed for Table 'dbo.Product'. "
At :line:48 char:35
+ foreach ($s in $scripter.EnumScript <<<< ($tbl)) { write-host $s }

However, when I comment out the output_file line

#$output_file="C:\Product.sql"

(which won’t set the Scripter options to write to file), it works fine and outputs the INSERT statments to the console.


Here’s the failing script, is there something I’m missing?

# Script INSERTs for given table
param 
(
  [string] $server,
  [string] $database,
  [string] $schema,
  [string] $table,
  [string] $output_file
)

$server="devdidb02"
$database="EPCTrunk_EPC"
$schema="dbo"
$table="Product"
$output_file="C:\Product.sql"

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null

$srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server
$db = New-Object ("Microsoft.SqlServer.Management.SMO.Database")
$tbl = New-Object ("Microsoft.SqlServer.Management.SMO.Table")
$scripter = New-Object ("Microsoft.SqlServer.Management.SMO.Scripter") ($server)

# Get the database and table objects
$db = $srv.Databases[$database]
$tbl = $db.tables | Where-object {$_.schema -eq $schema-and$_.name -eq $table} 

# Set scripter options to ensure only data is scripted
$scripter.Options.ScriptSchema = $false;
$scripter.Options.ScriptData = $true;

#Exclude GOs after every line
$scripter.Options.NoCommandTerminator = $true;

if ($output_file -gt "") 
{
  $scripter.Options.FileName = $output_file
  $scripter.Options.ToFileOnly = $true
}

# Output the script
foreach ($s in $scripter.EnumScript($tbl)) { write-host $s }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:00:15+00:00Added an answer on May 17, 2026 at 6:00 pm

    I ran both yours and Keith’s and it looks like the issue is in the path you are setting for the file. I was able to reproduce your error. You were using $output_file="C:\Product.sql". Then I changed the path to: $output_file="$home\Product.sql" it ran just fine and gave me the file.

    I am guessing that the reason for this is that I don’t have permission to write to c:\ which may be the problem you are having.

    BTW – my home dir in this case for me is my user folder for my login so I was able to find it there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a Powershell script which will compare two databases and come up with
I'm trying to get some json data from a remote website. I run my
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for
All of a sudden I am unable to run any web application in Visual
We would like to run a trigger on one database (A) that calls a
I don't know if this is strictly a programming question but here goes. I
I've started learning rails3 few days ago, and since today, every time I run
Tried to create a SQL 2005 DB project. In Vs, New Project >> Sql
Google analytics posted on their blog about an example Java program to extract data
I am trying to make a deployment war. I have the jdbc-mysql, activerecord-jdbcmysql-adapter and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.