title: Renaming a file on a network share using PowerShell
body: <p>So I have a SQL job setup to delete a file, then copy the latest, and then the last step is to rename it. The code works fine if I run it directly in a powershell window. However as a job step it fails. It's set to run as the same user that's used for the delete and copy steps. It has full control on the path. The error in the job history just says: 'Invalid Path: '\1.1.1.1\Backups\DB01_PROD_FULL_01252016.bak'.' Which is what $myfile below ends up being.</p>
  
  <pre><code>$mypath='Microsoft.PowerShell.Core\FileSystem::\\1.1.1.1\Backups\'
  $myfile=gci $mypath | sort LastWriteTime | select -last 1 -ExpandProperty FullName
  Rename-Item -path $myfile -newname 'DB.bak'
  </code></pre>