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...

Patrick Peters
  • 9,456
  • 7
  • 57
  • 106

2 Answers2

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

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • I use PowerShell ISE to test the call and when I call your code snippet I get an unhandled exception: Problem Event Name: PowerShell NameOfExe: powershell_ise.exe FileVersionOfSystemManagementAutomation: 6.0.6002.18111 InnermostExceptionType: System.AccessViolationException OutermostExceptionType: System.AccessViolationException DeepestPowerShellFrame: tem.Management.Automation.MethodInformation.Invoke DeepestFrame: nterop.UnsafeNativeMethods+IAdsContainer.GetObject ThreadName: Pipeli..ution Thread OS Version: 6.0.6002.2.2.0.274.38 Locale ID: 1033 – Patrick Peters Mar 24 '11 at 08:09
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)
Derick Schoonbee
  • 2,971
  • 1
  • 23
  • 39
  • - no authentication, - i am not using the Global Catalog (I only open the PowerShell ISE and calling the statements from above, - i have already disabled UAC so that is not needed and to be sure tested with a user that is already admin and still having that error. – Patrick Peters Mar 31 '11 at 09:50
  • Can you add an example of an authentication call on ADSI ? – Patrick Peters Mar 31 '11 at 10:36
  • Could not find a specific way to authenticate :( Docs only says that you should be part of Domain, Schema and Enterprise Admins, so I guess the context is on how you launch powershell. Another idea: How about using **AppCmd.exe** to delete the virtual dir? – Derick Schoonbee Mar 31 '11 at 11:17
  • I use a VM. The host of the VM is Win7 and on a domain, but the VM is not on the domain. Should that be the reason for errors ? Also I want not to change the existing .ps1 script; I want the script to run successfully in my VM... – Patrick Peters Mar 31 '11 at 12:33