title: Unable to enumerate databases on SQL Server from PowerShell
body: <p>I wish to check content of one database on server where I'm able to log into by means of Windows Authentication. Sounds really simple and many examples are provided over the Internet.</p>
  
  <p>I tried few examples and each fails on my machine. I suspect, that there might be problem during credentials conversion.</p>
  
  <p>My code (shortened) is as follows:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")
  
  $User=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
  $credentials = Get-Credential $saUser | Select-Object *
  $Pwd = $credentials.Password | ConvertFrom-SecureString 
  
  $targetConn = New-Object ('Microsoft.SqlServer.Management.Common.ServerConnection') ('myServer', $User, $Pwd)
  $targetServer = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $targetConn
  </code></pre>
  
  <p>till now there's no error message.</p>
  
  <p>When I type <code>$targetServer</code>, I don't see any objects listed (no Databases as well).</p>
  
  <p>When I tried to check <code>$targetServer.Databases</code>, I received:</p>
  
  <blockquote>
    <p>The following exception was thrown when trying to enumerate the collection: "Failed to connect to server mmyServer."</p>
  </blockquote>