Custom Powershell Provider偶尔会有一个空的PSDriveInfo

时间:2016-02-13 00:32:24

标签: powershell

我已经创建了一个自定义NavigationCmdletProvider并实现了所有必需的方法。我有一个自定义PSDriveInfo对象来管理与我正在使用的后端服务的连接,但我注意到Powershell似乎不断地使用null PSDriveInfo调用我的提供程序类上的方法。由于我需要PSDriveInfo来查找对象,因此在这种情况下我唯一的选择是返回false。

我添加了一堆日志记录,我得到的行如下:

Found item at path Foo\Bar\Baz.  Has DriveInfo? True
Item at path Foo\Bar\Baz doesn't exist.  Has DriveInfo? False
Exception thrown: 'System.Management.Automation.ItemNotFoundException' in System.Management.Automation.dll

有没有理由发生这种情况?有没有办法阻止这种情况发生?它会导致抛出大量的ItemNotFoundExceptions,通常至少在容器中的每个项目上,因此它会减慢速度并使查找错误源变得困难。

0 个答案:

没有答案