I am trying to implement a function in powershell that can reliably tell me if the directories referenced by two valid path names are indeed the same. It needs to be able to handle directories which are referenced by maps, by UNC paths, by junctions, possibly by junction on the file server, etc. etc.
Given the plethora of ways to refer to a directory, it seems the most reliable method of doing this is to write an empty file to the directory using one directory pathname, and then use the second pathname to test if the temporary file can be found under the second pathname. However, it turns out this may not be reliable.
We have a file server with a directory
S:\ that is shared out as
\\server\share. On the server we have the directories
S:\rootDir2, and a junction
S:\rootDir2\subDir => S:\rootDir1\subDir.
On an app server, I map
M:\ => \\server\share, so the app server sees
In powershell on the appserver, I create a file in
New-Item -ItemType File -Path `M:\rootDir1\subDir\testFile.txt`
We then immediately execute the two tests
$l_ret1 = test-path `M:\rootDir1\subDir\testFile.txt` $l_ret2 = test-path `M:\rootDir2\subDir\testFile.txt`
The returned result
$l_ret1 is consistently
$true, while the result
$l_ret2 is inconsistent without a significant time delay between creating the test file and testing for it. Is there any way to force Windows to "update" or "refresh" the information is has about files in
M:\rootDir2\subDir? I realize this may be the fault of the file server (window file server), but then the question just changes to, is there any way to force the file server to update its information?