I have put together a script that pulls a list of servers in the array and then tests outlook and owa connectivity to each. I also added a menu that allows a restart of selected services on all servers that show an error in connectivity.
What im wanting to do is be able to recycle or restart an IIS AppPool within the powershell session. So everytime I run get-wmiobject -class IISApplicationPool -namespace root\MicrosoftIISv2 I get the error:
"Invalid Namespace". Anyone know how I can 1. get a list of all the namespaces, and 2. recycle an iisapppool using get-wmiobject in powershell? Thanks..
To get a list of namespaces, do this:
gwmi -namespace root -class __namespace | ft name
I do not have the relevant namespace on this machine so I can't help with the second question.
To get a full list of WMI namespaces you need a little bit of recursion
function get-namespace {param ([string]$name) Get-WmiObject -Namespace $name -Class "__NAMESPACE" | foreach { "$name\" + $_.Name get-namespace $("$name\" + $_.Name) }}"root"get-namespace "root"
This starts at the root namespace and for each namespace in root chaecks for any namespaces and so on
You need to run it with elevated privileges as the security namespaces will throw an error
To recycle an application pool on IIS 7 - Windows 2008/2008 R2
Get-WmiObject -Namespace 'root\webadministration' -Class ApplicationPool -ComputerName <computer name> ` -Authentication 6 -Filter "Name='<application pool name>'" |Invoke-WmiMethod -Name Recycle
Run this with elevated privileges
You only need -Authentication 6 if you are accessing IIS remotely
More detail on this and investigating the structure of WMI in PowerShell and WMI - www.manning.com/siddaway2
Wonderful! I'm gonna try that. Cheers.
This is what I'm looking for. Ill post again if i have issues. Cheers.
You are very welcome