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);