創建 IIS 使用者後 PS 退出時出現“powershell 已停止工作”

創建 IIS 使用者後 PS 退出時出現“powershell 已停止工作”

在 Windows Server 2012 機器上,我使用 PS 建立一個新的 IIS 使用者(用於使用 MSDeploy 進行自動部署)。命令本身似乎工作正常——用戶已創建——但是一旦我退出 PowerShell 會話(鍵入exit或只是關閉命令視窗),就會顯示一個對話框,指出“powershell 已停止工作”,其中包含以下詳細資訊:

Problem signature:
  Problem Event Name:   PowerShell
  NameOfExe:    powershell.exe
  FileVersionOfSystemManagementAutomation:  6.2.9200.16628
  InnermostExceptionType:   Runtime.InteropServices.InvalidComObject
  OutermostExceptionType:   Runtime.InteropServices.InvalidComObject
  DeepestPowerShellFrame:   unknown
  DeepestFrame: System.StubHelpers.StubHelpers.GetCOMIPFromRCW
  ThreadName:   unknown
  OS Version:   6.2.9200.2.0.0.400.8
  Locale ID:    1033

有問題的 PS 指令是:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Management")
[Microsoft.Web.Management.Server.ManagementAuthentication]::CreateUser("Foo", "Bar")

為什麼會發生這種情況以及如何避免這種情況?

編輯:我還確認這是 PowerShell 4.0 的問題,因此我添加了該標籤。我也提交了連接

更新:Windows Server 2012 R2 似乎沒有相同的錯誤。

答案1

舊帖子,但我遇到了這個確切的問題並需要幫助。希望這個答案對其他人有幫助。

我在執行 PowerShell 4 的 Windows Server 2012 R2 上發生了這種情況。我所做的就是將此操作放在後台「執行緒」上,這樣主進程就不會被指示 PowerShell 崩潰的彈出視窗阻止。注意:只有當我執行透過 cmd 或 Microsoft Release Management 執行此操作的腳本時,PowerShell 才會崩潰。當直接在 PowerShell 視窗中呼叫腳本時,它沒有崩潰。即使它崩潰了,我想要腳本做的一切都在執行。腳本完成後才崩潰。

這是我的一些程式碼

param($password)

$jobScript = {
Try
{
    <# Clear the $Error variable so errors do not build up when debugging this script #>
    $Error.Clear()

    $userName = "SomeUser"

    If([ADSI]::Exists("WinNT://./$userName"))
    {
        Add-Type -Path "C:\windows\system32\inetsrv\Microsoft.Web.Management.dll"
        Add-Type -Path "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll"

        <# Set IIS Permissions on Default Web Site #>
        Try
        {
            $errorMessage = "Error setting IIS Permissions on Default Web Site for $userName"
            [Microsoft.Web.Management.Server.ManagementAuthorization]::Grant("$userName", "Default Web Site", $false)
            Write-Output "IIS Permissions set on Default Web Site for $userName"
        }
        Catch <# Tried catching the specific exception thrown, but was not working #>
        {
            Write-Output "IIS Permissions already set on Default Web Site for $userName"
        }
    }
    Else
    {
        $errorMessage = "The SomeUser user must be created prior to running this script"
        Write-Output $errorMessage
        Throw $errorMessage
    }
}
Catch
{
    # Signal failure to Microsoft Release Management
    Write-Error "$errorMessage - $Error"
}
}

$job = Start-Job $jobScript
Wait-Job $job
Receive-Job $job

答案2

已解決 - 啟動 powershell 或 powershell_ise 時出現「Powershell 已停止工作」錯誤。當「以管理員身分執行」啟動這些程式時,不會發生此錯誤。該網路中的所有 20 台實體和虛擬伺服器都遇到此問題。它似乎與Windows管理框架有關。所有伺服器都安裝了Windows Management Framework V5.1。

這解決了所有測試伺服器中的錯誤:

如果尚未安裝 Windows 管理框架,請安裝它。

https://docs.microsoft.com/en-us/powershell/scripting/wmf/overview?view=powershell-6

如果您的電腦已安裝 Windows Management Framework,請安裝此更新:

http://www.catalog.update.microsoft.com/Search.aspx?q=3191564

安裝後,重新啟動伺服器。

如果您覺得這有幫助,請投票。

相關內容