Powershell SMO Restore issue

Hey, I started a new job.  And just as I had hoped, I had the opportunity to learn new things.  One of the things I’m learning is Powershell.

I wanted to restore a database using SMO (SQL Server Management Objects), however, I kept getting a strange error.

My code worked for a while, and then all of a sudden, I started getting the error.

Cannot convert value of type “Microsoft.SqlServer.Management.Smo.Server” to type “Microsoft.SqlServer.Management.Smo.Server”

The error did not provide any more information.  Plus, it is really strange, how it could not convert a type into the same type.  But what it did not say was that it was expecting just a string – a name of the server.

This StackOverflow user answered his own question saying the same thing, but I did not believe him.


It turns out that it’s true.  Things started working again, once I passed a simple string into the functions.  Why my original code suddenly stopped working will be a mystery.

$dbFileList = $smoRestore.ReadFileList($ServerName);

This entry was posted in Powershell and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s