I am writing a batch file that executes a Powershell script that at one point loops items with UNC paths as attributes and uses Get-ChildItem
on those paths. In a minimal version, this is what is happening in my scripts:
Master.bat
powershell -ExecutionPolicy ByPass -File "Slave.ps1"
Slave.ps1
$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
}
The problem I'm running into is that when I run Master.bat, it fails at Get-ChildItem
with an error along the lines of
get-childitem : Cannot find path '\\remote-server\foothing' because it does not exist.
However, it seems to work perfectly fine if I run the Slave.ps1 file directly using Powershell. Why might this be happening only when the Master.bat file is run?
Things I have tried
- Prepending the UNC paths with
FileSystem::
with providers http://powershell.org/wp/2014/02/20/powershell-gotcha-unc-paths-and-providers/ - Making sure there are no strange characters in the actual paths
- Using the
-literalPath
parameter instead of the plain-path
parameter forGet-ChildItem
- Running
Get-ChildItem \\remote-server\foothing
in PowerShell and succeeding to verify connection to the remote server