title: Invalid path generated in remote command
body: <p>I am trying to run a command on a remote machine. I thought that I gave it a simple DIR command. However, the path generated keeps recursing the <code>Application Data</code> directory. PSVersion 5.0.10586.117</p>
  
  <pre><code>PS X:\Scripts\PSAutomation&gt; Get-Content .\stest2.ps1
  #Set-StrictMode -Version Latest
  [cmdletbinding()]
  Param()
  
  $Computername = "NOMURA"
  
  $Sess = New-PSSession $Computername
  
  $job = Invoke-Command `
      -ScriptBlock {
          &amp; cmd.exe /C DIR /S /B C:\Users\pwatson
          &amp; cmd.exe /C EXIT /B 7
      } `
      -Session $Sess -AsJob
  
  While ($job.State -ne "Completed")
  {
      Write-Verbose "waiting for it"
      Start-Sleep -Seconds 1             # &lt;Int32&gt;
  }
  
  $remoteoutput = Receive-Job -Id $job.Id -Keep
  $remoteoutput
  </code></pre>
  
  <p>Here is the execution output.</p>
  
  <pre><code>PS X:\Scripts\PSAutomation&gt; .\stest2.ps1 -Verbose
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  VERBOSE: waiting for it
  The directory name C:\Users\pwatson\AppData\Local\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Application Data\Application Data is too long.
      + CategoryInfo          : NotSpecified: (The directory n...ta is too long.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
      + PSComputerName        : NOMUrA
  
  The directory name C:\Users\pwatson\AppData\Local\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Apps\2.0\Data\JKANDEOW.ZBN is too long.
  The directory name C:\Users\pwatson\AppData\Local\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Application Data\Application Data\Application Data\Application
  Data\Application Data\Application Data\Apps\2.0\WA88X1RN.R7H\WQGJ5CWJ.XPH is too long.
  </code></pre>
  
  <p>This is not the same as <a href="https://stackoverflow.com/questions/6913784/multiple-layers-of-application-data-folders-windows7">Multiple layers of Application Data folders - Windows7</a></p>
  
  <p>The <code>DIR</code> command is being run on a remote machine. When I have an RDP session on the remote machine, this problem does not appear. It is only when I run <code>DIR</code> as a PowerShell remote job that the problem occurs.</p>