title: Cannot find path Powershell script on SQL Server Agent
body: <p>I've been searching all the internet and stackOF to and resolve this issue. 
  I am trying to automate a db restore using SQL Server Agent. The sql server agent job comprises of four steps 3 of which are tsql and one which is a powershell script.</p>
  
  <p>I have created a proxy with admin credentials so that the script can be run as admin. </p>
  
  <pre><code>    cd c:;
  $backuppath="Microsoft.PowerShell.Core\FileSystem::\\sharedcomputer\backup";
  $destpath="c:\tmp\";
  get-childitem -path $backuppath | where-object { -not $_.PSIsContainer } |
  
      sort-object -Property $_.CreationTime |
  
      select-object -last 1 | copy-item -Destination (join-path $destpath "byte.BAK");
  </code></pre>
  
  <p>It copies the .bak file from the source shared folder and places it in to tmp folder on the target.
  Whenever I run this through regular Powershell it works fine. 
  <strong>Whenever I try to run this from SQL server agent I get an error stating that it cannot find path.</strong></p>
  
  <p>I tried to even use net use to pass credentials for the shared folder. I am thinking it has to do with the fact that the folder has requirement for credentials. </p>
  
  <p>I have turned of password file sharing as well on the source server but for some reason when i use windows explorer to locate the shared file it still asks for credentials initially. Once its saved and cached I can then use powershell to cd in to that folder. But none of this works when its executed from sql server agent</p>