The following script will assign a given IIS object (site or virtual directory) to an existing application pool.
Note that it relies on a helper function to check if the pool exists.
It also makes sure that the current machine is Win2003 -- you can't specify pools in prior OS's. This OS check function was detailed in a previous blog
'****************************************************************************************** ' Name: SetAppPool
' Description: Assign the IIS Object to an Application Pool (IIS 6 only)
' Inputs: ObjApp (IIS Object), strAppPool (Pool to assign to)
'******************************************************************************************
sub SetAppPool(ObjApp, strAppPool)
if instr(GetOS_Remote("."), "2K3") <> 0 then
if AppPoolExists(strAppPool) then
ObjApp.AppPoolId = strAppPool
ObjApp.SetInfo
logmsg "Set App Pool to " & strAppPool
else
logmsg "Error: App Pool " & strAppPool & " Not Found"
end if
else
logmsg "Skip app pool setting; not a 2003 server"
end if
end sub
'******************************************************************************************
' Name: AppPoolExists
' Description: See if the application pool exists (IIS 6 only)
' Inputs: strAppPool
'******************************************************************************************
function AppPoolExists(strAppPool)
dim objPool
on error resume next
Set objPool = GetObject("IIS://localhost/w3svc/AppPools/" & strAppPool)
if err.number <> 0 then
AppPoolExists = false
else
AppPoolExists = true
end if
end function