Powershell Get-WMIObject失败,出现“Invalid Namespace”错误

这里的情况是:我试图使用PowerShell自动回收AppPool(Windows Server 2008与IIS7)。 我试图用这里find的PowerShell脚本来做到这一点 :

$appPoolName = $args[0] $appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | Where-Object {$_.Name -eq "W3SVC/APPPOOLS/$appPoolName"} $appPool.Recycle() 

但是,这会导致“无效的命名空间”错误:

get-wmiobject命名空间错误

我search了一下,发现我可能已经错过了IIS设置的IISpipe理脚本和工具angular色服务。

我怎样才能解决这个问题,或者,我可以回收一个没有WMI的Powershell的AppPool?

编辑

  • 澄清这是没有Hyper-V(SP2)x64的Windows Sever 2008 Enterprise。
  • 在x64版本的Powershell中运行上述命令会导致相同的错误。
  • 从32位运行Add-PSSnaping WebAdministration

    Add-PSSnapin:此机器上未安装Windows PowerShellpipe理单元“WebAdministration”。

  • 而在64位的环境下:

    Add-PSSnapin:没有为Windows PowerShell版本2注册pipe理单元。

  • (64bit) Get-PSSnapin -Registered什么都不返回

  • (32位) Get-PSSnapin -Registered返回Windows.ServerBackup,PSVersion 1.0

试试http://technet.microsoft.com/en-us/library/ee807823.aspx

 add-pssnapin WebAdministration Restart-WebItem 'IIS:\AppPools\DefaultAppPool' 

你在运行什么操作系统? 是x64还是x86? 这可能会影响加载的pipe理单元。 如果是x64,请尝试从x64和x86版本的PowerShell中embeddedpipe理单元。

x64位于C:\ Windows \ System32 \ WindowsPowerShell \ v1.0,x86位于C:\ Windows \ SysWow64 \ WindowsPowerShell \ v1.0

另外,当你跑步时你看到了什么

 Get-PSSnapin -Registered