创buildIIS用户后,PS退出时“powershell已停止工作”

在Windows Server 2012中,我正在使用PS创build一个新的IIS用户(用于使用MSDeploy进行自动化部署)。 该命令本身似乎工作正常 – 用户被创build – 但一旦我退出我的PowerShell会议(inputexit或只是closures命令窗口),一个对话框显示“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没有这个相同的错误。

旧post,但我遇到了这个确切的问题,需要帮助。 希望这个答案可以帮助别人。

在运行PowerShell 4的Windows Server 2012 R2上发生了这种情况。我的解决scheme并不完全是一个真正的解决scheme,但是它使我获得了我所需要的。 我所做的是把这个操作放在背景“线程”上,这样主进程就不会被popup窗口阻塞,表示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