使用ADSI时,Powershell脚本会返回异常

时间:2011-03-21 16:12:50

标签: exception powershell adsi

在Windows Server 2008(32位)上执行Power shell脚本(v1.0)时出现异常。

它在删除之前使用ADSI搜索虚拟目录。

我得到以下异常:

Exception calling "Find" with "2" argument(s): "Exception from HRESULT: 0x80005008"
At line:1 char:29
+ $iisMgr.psbase.children.find <<<< ("MyVirtualDir", $iisMgr.psbase.SchemaClassName)
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

这是代码:

$vDirPath = "IIS://localhost/W3SVC/1/Root"
$iisMgr = [adsi]$vDirPath
$iisMgr.psbase.children.find("MyVirtualDir", $iisMgr.psbase.SchemaClassName)

(编辑):我从几个博客中读到,必须启用IIS6管理兼容性角色服务才能安装ADSI提供程序,并且我已启用它,仍然有此例外...

2 个答案:

答案 0 :(得分:0)

你只尝试一个参数吗?

$iisMgr.psbase.children.find("MyVirtualDir")

我不知道那里,但是当我调用一个参数数量不好的方法时,我遇到了这种COM错误。

JP

答案 1 :(得分:0)

只是一些想法: