Script to Stop Application Pools on Windows

VB script to Stop Application Pools on Windows IIS 6

As  SysAdmin, We sometimes need to auto-stop some application pools in order to run a specific task like IIS logs cleanup.

This script will detect all application pools that are running and stop them.


=====================

myComputer = "."

Set objWMIService = GetObject ("winmgmts:\\" & myComputer & "\root\microsoftiisv2")

Set colItems = objWMIService.ExecQuery ("Select name from IISApplicationPoolSetting where AppPoolState = 2")

For Each objItems In colItems

poolname=objItems.name

WScript.Echo poolname

AppPoolStop(poolname)

Next



Function AppPoolStop(PoolName)

set PoolcolItems = objWMIService.ExecQuery ("Select name from IISApplicationPool where name='" & poolname & "'")


For Each objItem In PoolcolItems

objitem.Stop

Next

End Function

===============

Enter that script in a text file, save it with extension ".vbs". Copy it at C:\Windows\System32\

Run it manually or via a batch scheduler.


Thanks to Euk-marie. See the equivalent script by Euk-Marie to start the App Pool at https://www.eukhost.com/forums/f15/start-application-pool-simple-script-8937/

Advertisement

Filed under

Related articles

Level up your Tech Career with DjamgaTech PRO

Download the DjamgaTech PRO App on the Apple App Store to access hundreds of interactive prep questions, flashcards, and quizzes cleanly without ads.

Djamgatech PRO App
Download DjamgaTech PRO on the App Store 🚀

← All articles