title: How to connect to SQL Server LocalDB using Invoke-Sqlcmd?
body: <p>I have <code>sqlcmd.exe</code> from both SQLServer 2008 and SQLServer 2012:</p>
  
  <pre><code>PS C:\&gt; Get-Command sqlcmd.exe
  
  Definition
  ----------
  C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
  C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE
  </code></pre>
  
  <p>By modifying <code>$env:PATH</code> i force the use of <code>sqlcmd.exe</code> from SQL Server 2012:</p>
  
  <pre><code>PS C:\&gt; $env:PATH = ($env:PATH -split ";" | Where-Object { $_ -notlike "*\Microsoft SQL Server\100\*" }) -join ";"
  PS C:\&gt; Get-Command sqlcmd.exe
  
  Definition
  ----------
  C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE
  </code></pre>
  
  <p>The default instance of LocalDB is up and running, and owned by the current user:</p>
  
  <pre><code>PS C:\&gt; sqllocaldb i v11.0
  Name:               v11.0
  Version:            11.0.2318.0
  Shared name:
  Owner:              DOMAIN\me
  Auto-create:        Yes
  State:              Running
  Last start time:    12/06/13 18:17:57
  Instance pipe name: np:\\.\pipe\LOCALDB#08EDBEF0\tsql\query
  </code></pre>
  
  <p>Now, i can execute command on <code>(localdb)\v11.0</code> using <code>sqlcmd.exe</code></p>
  
  <pre><code>PS C:\&gt; sqlcmd.exe -S "(localdb)\v11.0" -Q "select 1"
  
  -----------
            1
  </code></pre>
  
  <p>But when trying the same with <code>Invoke-Sqlcmd</code> i get a connection error:</p>
  
  <pre><code>PS C:\&gt; Import-Module sqlps
  PS C:\&gt; Invoke-Sqlcmd -ServerInstance "(localdb)\v11.0" -Query "select 1"
  Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
  </code></pre>
  
  <p>What can i do to lmake <code>Invoke-Sqlcmd</code> connect to <code>(localdb)\v11.0</code> ?</p>