次の方法で共有


Powershell ISE crashes on exit while using Microsoft.Web.Management.dll

I was helping a customer other day on a stubborn crash whenever Powershell-ISE and Microsoft.Web.Management.dll are put together. While calling Microsoft.Web.Management.dll from Powershell-ISE or WMIprvse.exe, upon exit, it was throwing Runtime.InteropServices.InvalidComObject error while crashing the Powershell-ISE or WMIprvse.exe. Loading/calling the same DLL on the same machine from a C# console application did NOT exhibit this behavior.

Error details from Event Log:
- <Event xmlns="https://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Windows Error Reporting" />
<EventID Qualifiers="0">1001</EventID>
<Level>4</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2018-08-14T17:21:53.000000000Z" />
<EventRecordID>6366</EventRecordID>
<Channel>Application</Channel>
<Computer>MYMACHINE</Computer>
<Security />
</System>
- <EventData>
<Data>125883710853</Data>
<Data>5</Data>
<Data>PowerShell</Data>
<Data>Not available</Data>
<Data>0</Data>
<Data>PowerShell_ISE.exe</Data>
<Data>10.0.10586.117</Data>
<Data>Runtime.InteropServices.InvalidComObject</Data>
<Data>Runtime.InteropServices.InvalidComObject</Data>
<Data>unknown</Data>
<Data>System.StubHelpers.StubHelpers.GetCOMIPFromRCW</Data>
</EventData>
</Event>

Repro steps:
-First verify that IIS Default Web Site is up and running without any issues (we will be referencing this site in the powershell script)
-Launch Powershell ISE in admin mode
-Run following commands one after another

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Management")

if (-Not ([Microsoft.Web.Management.Server.ManagementAuthorization]::GetAuthorizedUsers("Default Web Site", $true, 0, 10) | ? Name -eq YourDomain\YourUserName)) {
$false
}
else {
$true
}
exit

-ISE crashes.
-Error logged in the Eventlog

 The solution:
Replace the exit with
[System.Environment]::Exit(0)