Search code examples
powershellscriptinguncpushd

Powershell "UNC paths are not supported" but I'm using Push-Location


I am running a command line program in powershell working on our \servername\files folder as the running folder. I get a "UNC paths are not supported" error even though I am using Push-Location (which is the only solution I find while googling). The simplest code that gives me this error is as follows:

Push-Location \\servername\files
cmd.exe \c ping 10.1.10.10
Pop-Location

Solution

  • PetSerAl is correct, you're getting this response from cmd, not Powershell. This would work if you had a PSDrive configured first, but I don't know if that is very efficient for your use case:

    New-PSDrive -Name S -PSProvider FileSystem -Root \\servername\files -Persist
    Push-Location
    Set-Location S:\
    cmd.exe /c ping 10.1.1.1
    Pop-Location
    Get-PSDrive S | Remove-PSDrive