title: Drop SQL Server database from powershell
body: <p>I have a SQL Server instance on my local computer called <code>.\SC</code>. I want to drop a database from that instance using a PowerShell script. I need to login with the <code>sa</code> user for my database.</p>
  
  <p>This is the code I have so far, but it doesn't work:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
  $srv = new-object Microsoft.SqlServer.Management.Smo.Server(".\SC")
  $conContext = $srv.ConnectionContext
  $conContext.LoginSecure = $FALSE
  $conContext.Login = "sa"
  $conContext.Password = "MyPlainTextPass"
  $srv2 = new-object Microsoft.SqlServer.Management.Smo.Server($conContext)
  $srv2.Databases
  </code></pre>
  
  <p>That last line is supposed to list the databases in my SQL instance... but it gives me this error:</p>
  
  <blockquote>
    <p>The following exception occurred while trying to enumerate the
    collection: "Failed to connect to server .\SC.". At line:1
    char:1
    + $srv2.Databases
    + ~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
        + FullyQualifiedErrorId : ExceptionInGetEnumerator</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>