title: Cannot bind RelocateFile when using Restore-SqlDatabase cmdlet
body: <p>I have SQL Server 2012 Developer installed on my machine. I also have the SQL Server 2014 management objects installed, too, which is probably the source of the problem.</p>
  
  <p>I'm writing a module to automate some common development tasks via Powershell. One of them is to simply copy an existing database to a new database.</p>
  
  <p>I'm aware there are three different ways to backup and restore: executing SQL statements, SMO objects, and the SQLPS cmdlets. I'm interested in the SQLPS route. Here's my function:</p>
  
  <pre><code>push-location
  import-module sqlps -disablenamechecking
  pop-location
  
  function Copy-Database {
      param (
          [string] $database,
          [string] $newDatabase
      )
  
      $backupFile = "$database-{0:yyyyMMddhhmmss}.bak" -f (get-date)
      backup-sqldatabase -serverinstance $defaultServerInstance -database $database -backupfile $backupFile -copyonly
  
      $solutionName = $newDatabase
  
      $mdf = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("MyDb_Data", "$defaultDatabaseRootPath\$solutionName\$newDatabase.mdf")
      $ldf = New-Object Microsoft.SqlServer.Management.Smo.RelocateFile("MyDb_Log", "$defaultDatabaseRootPath\$solutionName\$newDatabase.ldf")
  
      restore-sqldatabase -serverinstance $defaultServerInstance -database $newDatabase -backupfile $backupFile -RelocateFile @($mdf,$ldf)
  }
  </code></pre>
  
  <p>It backs up the database, but when it attempts the restore, I get the following error:</p>
  
  <blockquote>
    <p>Restore-SqlDatabase : Cannot bind parameter 'RelocateFile'. Cannot
    convert the "Microsoft.SqlServer.Management.Smo.RelocateFile" value of
    type "Microsoft.SqlServer.Management.Smo.RelocateFile" to type
    "Microsoft.SqlServer.Management.Smo.RelocateFile".</p>
  </blockquote>
  
  <p>This problem is also described here: <a href="https://stackoverflow.com/questions/26377356/problems-with-relocatefile-property-in-the-restore-sqldatabase-cmdlet">Problems with RelocateFile property in the Restore-SqlDatabase cmdlet</a></p>
  
  <p>I accept that the issue may be a conflict in assemblies. The accepted answer offers two suggestions:</p>
  
  <blockquote>
    <ol>
    <li>Make sure that the versions match.</li>
    <li>Use the Microsoft.SqlServer.Management.Smo.Restore.SqlRestore method instead of the Restore-SqlDatabase cmdlet.</li>
    </ol>
  </blockquote>
  
  <p>However, they only explain how to do #2. I want to know how to get this to work using the <code>Restore-SqlDatabase</code> cmdlet.</p>