title: Powershell move-item access denied
body: <p>Running a PS form with a button.  Button press does some stuff then calls a module.  I need to move a folder from D:\FolderName01\MyFolderName to D:\FolderName02 using the module.</p>
  
  <p>I am logged in as Administrator.  Server 2012-R2</p>
  
  <p>The code does <strong>NOT</strong> run when invoked from a button press and the automated script runs.</p>
  
  <p>It <strong>DOES</strong> run without problem when I am editing the code, I highlight it and use "Run Selection".</p>
  
  <p>This is literally the entire module.  Nothing else is being done.</p>
  
  <p>Code:</p>
  
  <pre><code> function MoveTheFolder($VariableName){
  
      if ( -not (Test-Path "D:\FolderName02") ) {
         md "D:\FolderName02"}
  
      cd -Path d:\
      Move-Item -Path "D:\FolderName01\$VariableName" -Destination "D:\FolderName02" -Force
  
   }
  </code></pre>
  
  <p>FolderName02 is created without issue.  $VariableName is passed in to the module and is correct based on a breakpoint analysis and the actual error message.  The original path is a DVD drive (.iso file on F:).  </p>
  
  <p>Error given is </p>
  
  <pre><code>move-item: Access to the path '[D:\FolderName01\$VariableName]' is denied.
  </code></pre>
  
  <p>I can move the folders manually using Windows Explorer, so they do not appear to be tied up with open applications.</p>