How to recycle an app pool on a remote machine using the command line
Solution 1
I am not sure regarding the particular vb script but I would recommend using "appcmd" (http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe)
- Add
%windir%\system32\inetsrv
to your path if it is not already - in a command prompt type:
appcmd recycle apppool "apppool_name"
Solution 2
Use powershell command to run it. Example:
Invoke-WMIMethod Recycle -Path "IIsApplicationPool.Name='W3SVC/APPPOOLS/apppoolname'" -Computer "WIN-Computername" -Namespace root\MicrosoftIISv2 -Authentication PacketPrivacy
Where apppoolname is your application pool name.
Where WIN-Computername is your remote/local server name
Solution 3
While not a vbs file command you could get vbs to execute this command line;
appcmd recycle apppool /apppool.name:string
The variable string is the name of the application pool that you want to recycle. For example, to recycle an application pool named Marketing, type the following at the command prompt, and then press ENTER:
appcmd recycle apppool /apppool.name:Marketing
Taken from technet
If it's too far away from what you want then my apologies.
Solution 4
Use powershell to execute command remotely on the server:
Invoke-Command -ComputerName <YOUR_IIS_SERVER_NAME> -ScriptBlock { Restart-WebAppPool -Name <YOUR_APP_POOL_NAME> }
Solution 5
I just tried it from a Windows XP machine to Windows 2008R2 machine. It worked. So you are definitely on the right track.
If you are looking for an alternative way, try this from a command prompt. At least the error message will be a little more specific, when it doesn't work.
wmic /namespace:"\\root\MicrosoftIISv2" /node:"**serverName**" path IISApplicationPool where (name like '%**DefaultAppPool**%') call recycle
Will I Am
Updated on July 09, 2022Comments
-
Will I Am almost 2 years
I have the following in a vbs file that i am trying to run from the command line:
strServerName = "ServerName" strAppPoolName = "DefaultAppPool" set objAppPools = GetObject("IIS://" & strServerName & "/w3svc/AppPools/" & strAppPoolName & "") objAppPools.Recycle()
And yet when I run the vbs from cmd line i get the following error:
Microsoft VBScript runtime error: ActiveX component can't create object: 'Get Object'_
I am running XP on my local machine, and the remote machine has IIS 7.
How can I get this to work?
-
Mike Mengell over 13 yearsDidn't see the remote server requirement. fair enough, prob not right. Powershell scripts will probably be the best way to go.
-
Will I Am over 13 yearssorry noob here, powershell??
-
Mike Mengell over 13 yearsPowershell is the new(ish) scripting language which is like vbs(x infinity) basics can be found here; msdn.microsoft.com/en-us/library/aa973757(v=vs.85).aspx. You probably also want something like this; windowsitpro.com/article/windows-management-instrumentation-wmi/…
-
ErikE over 9 yearsPsExec may be considered a security vulnerability by some company system administrators. Get permission before running it on company equipment.