开发者

Test-Path / System.IO.Directory::Exists not working as expected

I'm having trouble using the Powershell CmdLet Test-Path.

I created a Share on a Server (\\Servername\MyShare$), which allows one Group of users to just create a file and append data, while others users can just read and delete these files. The first group is not allowed to do anything else, including Read-Permissions, Read-Attributes and so on.

If I do a Test-Path on this folder as mem开发者_开发技巧ber of the "drop files only" group, it returns false. Even [System.IO.Directory]::Exists() returns false.

I am searching for a way to test if a directory exists without the need to have Read-Permissions or Read-Attributes rights. Any ideas?

Is this the correct behaviour of those two methods?

Regards, teamoo


Ok, if nobody want to venture ...

Here is a solution :

I'am not allowed to access to directory .\f1\f2 and .\f1\f3 does not exists.

PS C:\Silogix> Get-ChildItem .\f1\f2 -ErrorAction silentlycontinue
PS C:\Silogix> $Error[0].exception
L'accès au chemin d'accès 'C:\Silogix\f1\f2' est refusé.
PS C:\Temp\Temp> $Error[0].exception.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     UnauthorizedAccessException              System.SystemException

PS C:\Silogix> Get-ChildItem .\f1\f3 -ErrorAction silentlycontinue
PS C:\Silogix> $Error[0].exception.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ItemNotFoundException

So if you test $Error[0].exception.gettype() after the Get-Item you can understand why it's not accessible, so if it exists or not. You can call that "bricolage", but it's also a solution. Sorry for the french in the example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜