title: Powershell SMO: This method does not support scripting data
body: <p>I want to generate an import script for a MSSQL DB via Powershell (related to <a href="https://stackoverflow.com/questions/38633990">this question</a>).
  I tried doing this:</p>
  
  <pre><code>#Set-ExecutionPolicy RemoteSigned
  
  $DB_NAME = "&lt;&lt;dbName&gt;&gt;"
  
  [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
  
  $srv = new-object "Microsoft.SqlServer.Management.SMO.Server" "&lt;&lt;server&gt;&gt;"
  $conContext = $srv.ConnectionContext
  $conContext.LoginSecure = $false
  $conContext.Login = "&lt;&lt;user&gt;&gt;"
  $conContext.Password = "&lt;&lt;password&gt;&gt;"
  $srv = new-object Microsoft.SqlServer.Management.Smo.Server($conContext)
  $srv.SetDefaultInitFields([Microsoft.SqlServer.Management.SMO.View], "IsSystemObject")
  
  $db = $srv.databases[$DB_NAME]
  
  $scripter = new-object "Microsoft.SqlServer.Management.Smo.Scripter" $srv
  
  $scripter.Options.ScriptSchema = $false
  $scripter.Options.ScriptData = $true
  $scripter.Options.ScriptDrops = $false
  
  $scripter.Script($db)
  </code></pre>
  
  <p>But executing this throws an error:</p>
  
  <pre><code>"This method does not support scripting data"
  </code></pre>
  
  <p>I also tried to set the output file option but this doesn't change anything.</p>
  
  <p>Can you tell me what I did wrong?</p>
  
  <p>Thanks!</p>