title: Copying open files in Power shell
body: <p>i am new to PowerShell and i have managed to google my way to getting the following PowerShell Script together:</p>
  <pre><code>#System Variable for backup Procedure
  
   $date = Get-Date -Format d.MMMM.yyyy
   New-PSDrive -Name &quot;Backup&quot; -PSProvider Filesystem -Root &quot;\\server&gt;\&lt;path&gt;&quot;
   $source = &quot;\\server&gt;\&lt;path&gt;&quot;
   $destination = &quot;\\&lt;server&gt;\&lt;path&gt;\$date&quot;
   $path = test-Path $destination
  </code></pre>
  <h1>Email Variables</h1>
  <pre><code> $smtp = &quot;smudmug.mug&quot;
   $from = &quot;James Clegg &lt;email@email.com&gt;&quot;
   $to = &quot;James Clegg &lt;email@email.com&gt;&quot;
   $body = &quot;Hi All, &lt;/br&gt;&lt;/br&gt; Please find the back up log File for &lt;Server&gt;      attached.&lt;/br&gt;&lt;/br&gt; Back up complete on $date&lt;/br&gt;&lt;/br&gt;Kind Regards,&lt;/br&gt;&lt;/br&gt; James&quot;
   $subject = &quot;Backup of &lt;Server&gt; is Complete $date&quot;
  </code></pre>
  <h1>Backup Process started</h1>
  <pre><code>if ($path -eq $true) {
  write-Host &quot;Folder Already exists&quot;
  Remove-PSDrive &quot;Backup&quot;  
  } elseif ($path -eq $false) {
          cd backup:\
          copy-Item -Recurse $source -passthru -Destination $destination
          $backup_log = Dir -Recurse $destination | out-File      &quot;$destination\backup_log.txt&quot;
          $attachment = &quot;$destination\backup_log.txt&quot;
          #Send an Email to User 
          send-MailMessage -SmtpServer $smtp -From $from -To $to -Subject        $subject -Attachments $attachment -Body $body -BodyAsHtml
          write-host &quot;Backup Successful&quot;
          cd c:\
  
       Remove-PSDrive &quot;Backup&quot;  
       }
  
     cmd /c pause | out-null
  </code></pre>
  <p>Can someone please help me which what i need to add to allow files in use to be copied.</p>
  <p>Kind regards,</p>
  <p>James</p>