Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here's the situation: I'm trying to use PowerShell to automatically recycle an AppPool (Windows Server 2008 with IIS7). I'm attempting to do this with the PowerShell script found here:

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

However, this results in a 'Invalid Namespace' error:

get-wmiobject namespace error

I googled around and found that I may have been missing the "IIS Management Scripts and Tools" role service which I have since set up for IIS.

How can I fix this issue, or alternatively, can I recycle an AppPool with Powershell without WMI?

Edit

  • To clarify this is Windows Sever 2008 Enterprise without Hyper-V (SP2) x64.
  • Running the above command in the x64 version of Powershell results in the same error.
  • Running Add-PSSnaping WebAdministration from 32bit:

    Add-PSSnapin : The Windows PowerShell snap-in 'WebAdministration' is not installed on this machine.

  • And in the 64bit environment:

    Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.

  • (64bit) Get-PSSnapin -Registered returns nothing

  • (32bit) Get-PSSnapin -Registered returns Windows.ServerBackup, PSVersion 1.0
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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

add-pssnapin WebAdministration
Restart-WebItem 'IIS:\AppPools\DefaultAppPool'
share|improve this answer
    
I tried that, and get an error that the snap-in 'WebAdministration' is not installed on this machine... However, I do have c:\windows\system32\inetsrv\Microsoft.Web.Administration.dll and can apparently create and manipulate a web administration obeject as demonstrated here: blogs.iis.net/tobintitus/archive/2006/11/30/… ...ideas? –  Factor Mystic Dec 6 '10 at 21:12
    
@Factor: try reinstalling the snapin: iis.net/download/PowerShell and see if it helps. –  MattB Dec 8 '10 at 14:45
    
Success: Downloaded and reinstalled the 64bit version - now I have Restart-WebItem in the 32bit prompt (but not 64bit prompt). This is good enough, however - thanks! –  Factor Mystic Dec 8 '10 at 15:06
add comment

What OS are you running? Is it x64 or x86? This can have an impact on loading of the snapin. If x64, try loding the snapin from both x64 and x86 versions powershell.

x64 is in C:\Windows\System32\WindowsPowerShell\v1.0 and x86 is in C:\Windows\SysWow64\WindowsPowerShell\v1.0

Also, what do you see when you run

Get-PSSnapin -Registered
share|improve this answer
    
Good thought- edited question with response –  Factor Mystic Dec 8 '10 at 14:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.