I've used this VBScript successfully. YMMV but at least it's a starting point.
' set a few constants
const CreateNewApplicationPool = true
const UseExistingApplicationPool = false
' Load the Metabase entry if the target directory does exist
Set IISWebDirObj = GetObject("IIS://" & objServer & "/W3SVC/" & objSiteID & "/Root/" & objApp)
if Err.Number <> 0 then
Err.Clear
' Create the Metabase entry if the target directory does NOT exist
Set IISWebDirRootObj = GetObject("IIS://" & objServer & "/W3SVC/" & objSiteID & "/Root")
Set IISWebDirObj = IISWebDirRootObj.Create("IISWebDirectory", objApp)
end if
' Assign an existing app pool to the target directory
' Try AppCreate or Appcreate2 to create the app pool at the same time
' or try using CreateNewApplicationPool for last parameter
IISWebDirObj.AppCreate3 2, objSvcPool, UseExistingApplicationPool
' set the name so it doesn't show up as: Default Application
IISWebDirObj.AppFriendlyName = objSvcPool
IISWebDirObj.SetInfo
' refresh the object in memory so we can change the app pool
IISWebDirObj.GetInfo
IISWebDirObj.AppPoolId = objSvcPool
IISWebDirObj.SetInfo