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:
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
Try http://technet.microsoft.com/en-us/library/ee807823.aspx
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