Powershell script returns exception when using ADSI

3

I get exceptions when executing a Power shell script (v1.0) on Windows Server 2008 (32 bit).

It uses ADSI for searching a virtual directory before its deletion.

I get the following exception:

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

This is the code:

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

(edit): from several blogs I read that the IIS6 Management Compatibility role service must be enabled to get the ADSI provider installed, and I already have it enabled, still having this exception...

exception
powershell
adsi
asked on Stack Overflow Mar 21, 2011 by Patrick Peters • edited Mar 22, 2011 by Patrick Peters

2 Answers

0

Do you try with only one parameter ?

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

I dont know there, but I've this kind of COM error when I invoke a method with the bad number of arguments.

JP

answered on Stack Overflow Mar 23, 2011 by JPBlanc
0

Just some ideas:

  • Do you authenticate when doing ADSI interaction?
  • I guess you are not making use of the Global Catalog as per your example of $vDirPath. In any case have a peek at See How to Modify Attributes That Replicate to the Global Catalog
  • Try running your Powershell session with elevated user rights (Right-Click Run As Administrator)
answered on Stack Overflow Mar 30, 2011 by Derick Schoonbee

User contributions licensed under CC BY-SA 3.0