title: How to bring SQL Server database out of "restoring" mode using SMO
body: <p>I'm bringing databases out of log shipping, trying to use SMO to do it. I'm attempting to mimic the following T-SQL using SMO:</p>
  
  <pre><code>restore database &lt;database name&gt; with recovery
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code># select secondary_database from msdb.dbo.log_shipping_secondary_databases
  $dsSecLSDB = $secInst.Databases["MSDB"].ExecuteWithResults("select secondary_database from log_shipping_secondary_databases")
  $secLSDB = $dsSecLSDB.Tables.Rows
  
  foreach($db in $secLSDB.secondary_database) {
          write-host "Restoring database (bringing online)..."
          $secRestrObj = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Restore -Property @{
              Action = 'Database';
              Database = $db;
              NoRecovery = $FALSE;
          }
  
          $secRestrObj.SqlRestore($secInst);
          write-host "Done with restore."
  }
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p><em>Microsoft.SqlServer.Management.Smo.PropertyNotSetException: To accomplish this action, set property Devices</em></p>
  </blockquote>
  
  <p>The available options for <code>DeviceType</code> (from <a href="https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.devicetype(v=sql.105).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.devicetype(v=sql.105).aspx</a>) are:</p>
  
  <ul>
  <li>LogicalDevice     </li>
  <li>Tape     </li>
  <li>File     </li>
  <li>Pipe   </li>
  <li>VirtualDevice</li>
  </ul>
  
  <p>The problem is, I don't know which <code>DeviceType</code> to create. My guess is <code>LogicalDevice</code> but I don't know the value of it. Has anyone done this before?</p>