1

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

2 Answers 2

3

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

add-pssnapin WebAdministration
Restart-WebItem 'IIS:\AppPools\DefaultAppPool'
3
  • 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? Dec 6, 2010 at 21:12
  • @Factor: try reinstalling the snapin: iis.net/download/PowerShell and see if it helps.
    – MattB
    Dec 8, 2010 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! Dec 8, 2010 at 15:06
0

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
1
  • Good thought- edited question with response Dec 8, 2010 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .