Trying to connect to an instance of SQL Server 2008 on a server we'll call Sputnik. There are no firewalls in between the two devices.
Right now I'm just trying to list databases
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null
$servername = "Sputnik"
$remoteServer = New-Object("Microsoft.SqlServer.Management.Smo.Server") $servername
$remoteServer.databases
The following error message occurs:
The following exception was thrown when trying to enumerate the collection:
"Failed to connect to server Sputnik.".
At line:1 char:15 + $remoteServer. <<<< databases
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : ExceptionInGetEnumerator
A couple of suggestions: Since you're using Windows authentication does your Windows login have access to the remote server and are both machines on the same domain? Are you able to connect using other tools? One quick way to do so is to setup and ODBC connection: ODBC Data Source >> Add SQL Server >> Test Connection