title: Moving files on network shares
body: <p>I want to automate many of my daily tasks via powershell.  One process that we have is imaging desktops after hours.  Once this operation is complete, the image files need to be moved off the server hard drives to a network drive.  I'm writing an app to run as a service on my machine that will call the powershell script and knock everything out, alerting me only when there is a problem.</p>
  
  <p>I set up a directory on the server for scripts.  It works fine if I call my script, FileCopy.ps1, from the server:</p>
  
  <pre><code>copy-item C:\scripts\myFile1.txt -destination C:\scripts\myFile2.txt
  </code></pre>
  
  <p>However, in my .Net app, I call the script from my local machine:  </p>
  
  <pre><code>RunScript(LoadScript(@"\\Server\ServerShare\FileCopy.ps1")); 
  </code></pre>
  
  <p>Doesn't work.  That's because it sees C:\scripts as being on the local machine.  So, I change it:</p>
  
  <pre><code>copy-item \\Server\ServerShare\myFile1.txt -destination \\Server\ServerShare\myFile2.txt
  </code></pre>
  
  <p>Doesn't work.  I add another line to the script:</p>
  
  <pre><code>copy-item \\Server\ServerShare\myFile1.txt -destination \\Server\ServerShare\myFile2.txt
  get-childitem \\Server\ServerShare | format-table name
  </code></pre>
  
  <p>It still doesn't copy the file, but it <strong>does</strong> return the contents of the scripts directory on the server.</p>
  
  <p>So I go back to the server and run the script with the UNC paths in place - powershell returns an error</p>
  
  <pre><code>Copy-Item : Access to the path '\\Server\ServerPath\myFile2.txt' is denied.
  </code></pre>
  
  <p>That seems to be the root of the problem.  Any idea how I can get around this?  I'm logged onto the server as an admin.</p>