title: Running Get-ChildItem on UNC path works in Powershell but not in Powershell run in batch file
body: <p>I am writing a batch file that executes a Powershell script that at one point loops items with UNC paths as attributes and uses <code>Get-ChildItem</code> on those paths. In a minimal version, this is what is happening in my scripts:</p>
  
  <p><strong>Master.bat</strong></p>
  
  <pre><code>powershell -ExecutionPolicy ByPass -File "Slave.ps1"
  </code></pre>
  
  <p><strong>Slave.ps1</strong></p>
  
  <pre><code>$foo = @{Name = "Foo"}
  $foo.Path = "\\remote-server\foothing"
  
  $bar = @{Name = "Bar"}
  $bar.Path = "\\remote-server\barthing"
  
  @( $foo, $bar ) | ForEach-Object {
      $item = Get-ChildItem $_.Path
      # Do things with item
  }
  </code></pre>
  
  <p>The problem I'm running into is that when I run <strong>Master.bat</strong>, it fails at <code>Get-ChildItem</code> with an error along the lines of</p>
  
  <pre><code>get-childitem : Cannot find path '\\remote-server\foothing' because it does not exist.
  </code></pre>
  
  <p>However, it seems to work perfectly fine if I run the <strong>Slave.ps1</strong> file directly using Powershell. Why might this be happening only when the <strong>Master.bat</strong> file is run?</p>
  
  <p><strong>Things I have tried</strong></p>
  
  <ul>
  <li>Prepending the UNC paths with <code>FileSystem::</code> with providers <a href="http://powershell.org/wp/2014/02/20/powershell-gotcha-unc-paths-and-providers/">http://powershell.org/wp/2014/02/20/powershell-gotcha-unc-paths-and-providers/</a></li>
  <li>Making sure there are no strange characters in the actual paths</li>
  <li>Using the <code>-literalPath</code> parameter instead of the plain <code>-path</code> parameter for <code>Get-ChildItem</code></li>
  <li>Running <code>Get-ChildItem \\remote-server\foothing</code> in PowerShell and succeeding to verify connection to the remote server</li>
  </ul>