Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Can't use test-path for \\?\ paths

$
0
0

I have a problem on only one server that I am unable to use Test-Path successfully when using paths prefixed with \\?\. On every other server we have the command works as expected (that's a mixture of 2008R2 & 2012, PS v2 & 3).

Does anyone know what settings I should check that could cause this behaviour or have any ideas on how I could debug it?

For now I've worked around the problem by checking for the GUID I want in the output of wmic volume, but I would like to find a solution to correct this oddity as the workaround is a bit messy and unobvious. I've included some results below for your information.

The problematic server is 2008R2, Powershell is v2.0.

Thanks for any assistance.

The volume I'm searching for is mounted as Z:, as can be seen from the output of mountvol:

    \\?\Volume{f65f14d3-27be-4172-9359-219a0be0e7d4}\
        Z:\

Test-Path always generates the Illegal characters in path error on all our servers when doing this testing, but the error doesn't seem to affect the result - on the other servers it returns an error and $true if the volume is present.

Test-Path -LiteralPath "\\?\Volume{f65f14d3-27be-4172-9359-219a0be0e7d4}\"

Test-Path : Illegal characters in path.
At line:1 char:10
+ Test-Path <<<<  -LiteralPath "\\?\Volume{f65f14d3-27be-4172-9359-219a0be0e7d4}\"
    + CategoryInfo          : InvalidArgument: (\\?\Volume{f65f...-219a0be0e7d4}\:String) [Test-Path], ArgumentException
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

False

PS C:\Windows\system32> Test-Path -LiteralPath "\\?\Z:\"
Test-Path : Illegal characters in path.
At line:1 char:10
+ Test-Path <<<<  -LiteralPath "\\?\Z:\"
    + CategoryInfo          : InvalidArgument: (\\?\Z:\:String) [Test-Path], ArgumentException
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

False
PS C:\Windows\system32> Test-Path -LiteralPath "Z:"
True
PS C:\Windows\system32>

 

Further testing shows that whenever using \\?\ Test-Path always returns false, for example:

PS C:\Windows\system32> Test-Path -LiteralPath "\\?\C:\"
Test-Path : Illegal characters in path.
At line:1 char:10
+ Test-Path <<<<  -LiteralPath "\\?\C:\"
    + CategoryInfo          : InvalidArgument: (\\?\C:\:String) [Test-Path], ArgumentException
    + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand

False
PS C:\Windows\system32> Test-Path -LiteralPath "C:\"
True
PS C:\Windows\system32>


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>