PowerShell Test-Path returns False when testing a network share

user3418092 picture user3418092 · Mar 14, 2014 · Viewed 43.5k times · Source

The user has appropriate permissions to read the share, and the share maps properly. This issue seems to happen only in PowerShell v2.0.

If I remove all mapped drives, remap one drive, and run Test-Path:

net use /delete * /y
net use G: \\somefileserver\share
Test-Path G:\

Test-Path returns False, even though the drive is clearly mapped, and I can access it through Windows Explorer.

If I close the PowerShell session, and open a new session, Test-Path returns True, as it should. Any ideas on, (A): what could be causing this, and how do I make it work properly? or (B): Is there another way to test for the existence of a network drive besides Test-Path? I am attempting to write a logon script to map user's network drives and this behavior is driving me insane.

Answer

Daniel Lindegaard picture Daniel Lindegaard · Apr 10, 2017

I do think I found the answer with this:

Test-Path $('filesystem::\\Server\share$\install.wim')