Backup database from default (unnamed) sql server instance with powershell.

Posted by sparks on Server Fault See other posts from Server Fault or by sparks
Published on 2011-01-28T22:49:32Z Indexed on 2011/01/28 23:28 UTC
Read the original article Hit count: 305

Filed under:
|
|
|

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

© Server Fault or respective owner

Related posts about sql-server

Related posts about backup