Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Here is a link to the IIS 6.0 scripts at Microsoft that most of these were hacked from. http://www.microsoft.com/technet/scriptcenter/scripts/iis/iis6/default.mspx
There are not any UDF's for creating a site because I rely on the Windows 2003 IISWEB.VBS to create and delete sites. I also use iiscnfg.vbs to export and import configurations. BradSjue
;============================================================================== ; LISTIISSITES ; This will list the IIS sites and return a TAB delimited string with the site name ; Port binding and the Site comment ; To list this on the local computer just run ex. ; sites = ListIISSites(".", "", "") ;============================================================================== #DefineFunction ListIISSites(sCompName, Username, Password) siteslist = '' ;Intialize the list we will return objLocator = ObjectCreate("WbemScripting.SWbemLocator") ErrorMode(@OFF) objService = objLocator.ConnectServer(sCompName,"root/microsoftiisv2",Username,Password) ErrorMode(@CANCEL) err = LastError ( ) If err != 0 Then Return StrCat("ERROR-WMI Connect-", err) objSecurity = objService.Security_ objSecurity.ImpersonationLevel = 3 ; query instances for the IISWebServerSettings query = "Select * From IIsWebServerSetting" colInstances = objService.ExecQuery(query) ; loop once for each instance ForEach objInstance In colInstances ;Check if Object is EMPTY type = ObjectTypeGet(objInstance) If type=="EMPTY" Then Break ; obtain properties bindings = objInstance.ServerBindings cnt = ArrInfo(bindings,1)-1 For i = 0 To cnt line = StrCat(objInstance.ServerComment, "|", objInstance.ServerBindings(i).Port, "|", objInstance.Name) siteslist = StrCat(siteslist,line,@TAB) Next Next ; Close object handles ObjectClose(colInstances) ObjectClose(objSecurity) ObjectClose(objService) ObjectClose(objLocator) Return siteslist #EndFunction ;============================================================================== ; LISTIISAPPPOOLS ; This will list the IIS application pools and return a TAB delimited string with the pool names ; To list this on the local computer just run ex. ; pools = ListIISAppPools(".", "", "") ;============================================================================== #DefineFunction ListIISAppPools(sCompName, Username, Password) poolslist = '' ;Intialize the list we will return objLocator = ObjectCreate("WbemScripting.SWbemLocator") ErrorMode(@OFF) objService = objLocator.ConnectServer(sCompName,"root/microsoftiisv2",Username,Password) ErrorMode(@CANCEL) err = LastError ( ) If err != 0 Then Return StrCat("ERROR-WMI Connect-", err) objSecurity = objService.Security_ objSecurity.ImpersonationLevel = 3 ; query instances for the IISWebServerSettings query = "Select * From IIsApplicationPool" colInstances = objService.ExecQuery(query) ; loop once for each instance ForEach objInstance In colInstances ;Check if Object is EMPTY type = ObjectTypeGet(objInstance) If type=="EMPTY" Then Break ; obtain properties poolname = objInstance.Name poolslist = StrCat(poolslist,poolname,@TAB) Next ; Close object handles ObjectClose(colInstances) ObjectClose(objSecurity) ObjectClose(objService) ObjectClose(objLocator) Return poolslist #EndFunction ;============================================================================== ; CREATEIISAPPPOOL ; This function will create an application pool within IIS ; Probably should migrate this function to WMI sometime but it works now ;============================================================================== #DefineFunction CreateIISAppPool(sCompName, AppPoolName) iisobj = StrCat("IIS://", sCompName, "/W3SVC/AppPools") appPools = GetObject(iisobj) appPool = appPools.Create("IIsApplicationPool", AppPoolName) appPool.SetInfo appPool.PeriodicRestartTime=720 appPool.AppPoolAutoStart=@TRUE appPool.AppPoolQueueLength=3000 appPool.IdleTimeout=0 appPool.OrphanWorkerProcess=@FALSE appPool.PeriodicRestartMemory=1843200 appPool.PeriodicRestartRequests=0 appPool.PeriodicRestartTime=720 appPool.PingInterval=30 appPool.PingResponseTime=90 appPool.PingingEnabled=@TRUE appPool.RapidFailProtection=@TRUE appPool.RapidFailProtectionInterval=5 appPool.RapidFailProtectionMaxCrashes=5 appPool.LogEventOnRecycle=255 appPool.SetInfo appPools = '' ;Close the object Return @TRUE ;Return a 1 for a successful creation #EndFunction ;============================================================================== ; DELETEIISAPPPOOL ; This function will Delete an application pool within IIS ; Usage: DeleteIISAppPool("CHIG_Pool") ;============================================================================== #DefineFunction DeleteIISAppPool(sCompName, AppPoolName) iisobj = StrCat("IIS://", sCompName, "/W3SVC/AppPools") appPools = GetObject(iisobj) appPool = appPools.Delete("IIsApplicationPool", AppPoolName) appPools = '' ; Close the object Return @TRUE ;Return a 1 for a successful deletion #EndFunction ;============================================================================== ; DELETEAPPLICATIONADSI ; This function will delete an application from a virtual directory using ADSI. This is used ; to remove the application that Citrix creates for the site, so that we can create ; another application in a different application pool ;============================================================================== #DefineFunction DeleteApplicationADSI(sCompName, Metapath) ThisSite = StrCat("IIS://", sCompName, "/", Metapath) iisobj = ObjectGet(ThisSite) iisobj.AppDelete iisobj.SetInfo iisobj = "" ;Closes the object Return #EndFunction ;============================================================================== ; LISTPOOLAPPS ; This function will list the applications within an application pool within IIS ; It returns the list of applications (metapath) ; Usage: ListApps("CHIG_Pool") ;============================================================================== #DefineFunction ListPoolApps(sCompName, AppPoolName) appslist = '' iisobj = StrCat("IIS://", sCompName, "/W3SVC/AppPools/", AppPoolName) appPools = GetObject(iisobj) apparr=appPools.EnumAppsInPool() cnt = ArrInfo(apparr,1)-1 If cnt <0 appPools = '' ;Close the object Return 0 EndIf For i = 0 To cnt thisapp = apparr[i] ; Message(thisapp, thisapp) appslist = StrCat(appslist,thisapp,@TAB) Next appPools = '' ;Close the object Return appslist #EndFunction ;============================================================================== ; LISTSITEAPPS ; This function will list the application pool for a site within IIS ; It returns the name of the pool for a given metabase path ; Usage: ListSiteApps("mycomputer", "W3SVC/917792675/Root") ; Note: If you do not have a root or some other path it will always return the ; default application pool. ;============================================================================== #DefineFunction ListSiteApps(sCompName, MetaPath) ThisSite = StrCat("IIS://", sCompName, "/", Metapath") SiteObj = GetObject(ThisSite) SiteApp=SiteObj.AppPoolId SitObj = '' ;Close the object. Return SiteApp #EndFunction ;============================================================================== ; CREATEAPPLICATIONADSI ; This function will create an application in a virtual directory using ADSI. ; This uses ADSI because it is much quicker than WMI for it's functions. ;============================================================================== #DefineFunction CreateApplicationADSI(sCompName, Metapath, Client, AppPoolName) ThisSite = StrCat("IIS://", sCompName, "/", Metapath") iisobj = ObjectGet(ThisSite) iisobj.AppCreate (@TRUE) iisobj.AppFriendlyName=Client iisobj.AppPoolId=AppPoolName iisobj.AppIsolated=2 iisobj.SetInfo iisobj = "" ;Closes the object Return #EndFunction ;============================================================================== ; GETVIRTUALDIRFILEPATH ; This function will get the physical path to the files for a given site. ;============================================================================== #DefineFunction GetVirtualDirFilePath(sCompName, Metapath) ThisSite = StrCat("IIS://", sCompName, "/", Metapath") iisobj = ObjectGet(ThisSite) vdirpath = iisobj.path iisobj = "" ;Closes the object Return vdirpath #EndFunction ;============================================================================== ; THIS FUNCTION WAS DUPLICATED WITH THE ADSI VERSION ; DELETEAPPLICATION - WMI ; This function is needed to delete an application from a Virtual Directory. This is because Citrix ; when it creates the site creates an application and assigns it to the CitrixWebInterface4.2ApplicationPool ; I have every site go to it's own pool for client isolation from one another. Usage is ; delapp = DeleteApplication(".", "", "", "W3SVC/587721366/Root/Prod") ;============================================================================== #DefineFunction DeleteApplication(sCompName, Username, Password, MetaPath) objLocator = ObjectCreate("WbemScripting.SWbemLocator") ErrorMode(@OFF) objService = objLocator.ConnectServer(sCompName,"root/microsoftiisv2",Username,Password) ErrorMode(@CANCEL) err = LastError ( ) If err != 0 Then Return StrCat("ERROR-WMI Connect-", err) objSecurity = objService.Security_ objSecurity.ImpersonationLevel = 3 ; query instances for the IISWebServerSettings query = StrCat("Select * From IIsWebVirtualDir Where Name = '", MetaPath, "'") colInstances = objService.ExecQuery(query) ; loop once for each instance ForEach objInstance In colInstances ;Check if Object is EMPTY type = ObjectTypeGet(objInstance) If type=="EMPTY" Then Break objInstance.AppDelete(@TRUE) Next ; Close object handles ObjectClose(colInstances) ObjectClose(objSecurity) ObjectClose(objService) ObjectClose(objLocator) Return #EndFunction ;============================================================================== ; LISTIISVDIRS ; This will list the IIS virtual directories ; To list this on the local computer just run ex. ; vdirs = ListIISVDirs(".", "", "") ;============================================================================== #DefineFunction ListIISVDirs(sCompName, Username, Password) vdirslist = '' ;Intialize the list we will return objLocator = ObjectCreate("WbemScripting.SWbemLocator") ErrorMode(@OFF) objService = objLocator.ConnectServer(sCompName,"root/microsoftiisv2",Username,Password) ErrorMode(@CANCEL) err = LastError ( ) If err != 0 Then Return StrCat("ERROR-WMI Connect-", err) objSecurity = objService.Security_ objSecurity.ImpersonationLevel = 3 ; query instances for the IISWebServerSettings query = "Select * From IIsWebVirtualDir" colInstances = objService.ExecQuery(query) ; loop once for each instance ForEach objInstance In colInstances ;Check if Object is EMPTY type = ObjectTypeGet(objInstance) If type=="EMPTY" Then Break ; obtain properties name = objInstance.Name vdirslist = StrCat(vdirslist,name,@TAB) Next ; Close object handles ObjectClose(colInstances) ObjectClose(objSecurity) ObjectClose(objService) ObjectClose(objLocator) Return vdirslist #EndFunction ;============================================================================== ; UDFWRITELOG ; This function will write out the Log file and a message with the date prepended. ;============================================================================== #DefineFunction UDFWriteLog(LogFile, LogText) CurrDate = TimeDate ( ) handle = FileOpen(LogFile, "APPEND") Logme = StrCat(CurrDate, @TAB, @TAB, LogText) FileWrite(handle, Logme) FileClose(handle) Return #EndFunction ;UDFWriteLog ;============================================================================== ; ENSURE2003 ; This function verifies that the OS is Windows 2003, if not it goes to the ExtErr function ;============================================================================== #DefineFunction Ensure2003() MINORVER = WinVersion(0) MAJORVER = WinVersion(1) BUILDVER = WinVersion(2) CSDVER = WinVersion(3) PLATFORM = WinVersion(4) WinVer = StrCat(MajorVer,MinorVer,Platform) If WinVer != 524 Then ExtErr("Windows 2003 is required to run this program") Return #EndFunction ;============================================================================== ; EVENTLOGWRITE ; This function writes an event to the event log. It is logged under WSH ; but provides an easy mechanism to get events into the event log ; Below are the values for the severity ;Type Value ;0 SUCCESS ;1 ERROR ;2 WARNING ;4 INFORMATION ;8 AUDIT_SUCCESS ;16 AUDIT_FAILURE ; Ex. EventLogWrite(1, "Premature Failure") ;============================================================================== #DefineFunction EventLogWrite(sev, logentry) WshShell = CreateObject("WScript.Shell") WshShell.LogEvent(sev, logentry) Return #EndFunction ;============================================================================== ; PINGSRVR ; This function uses the ipPing from the IP Grabber extender to ping the server ; for the status either ALIVE or DOWN ;============================================================================== #DefineFunction PingSrvr(scompname) x=ipPing(scompname,5) If x == 0 ; err=ipGetLastErr() Return "DOWN" Else Return "ALIVE" EndIf #EndFunction
Article ID: W17197
File Created: 2007:07:03:14:28:42
Last Updated: 2007:07:03:14:28:42