ajtsystems
IS-IT--Management
Hi,
I have a script which pulls from IIS7 the application path, the application pool and the site name. The apppool comes from a different part of the WMI database so needs a different object to connect. Here is my code:
Const strInFile = "hostlist.txt"
Const ForReading = 1
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objInFile, objOutFile
Set objInFile = objFSO.OpenTextFile(strInFile,ForReading, False)
Do Until objInFile.AtEndOfStream
strUser = "james"
strpassword= "jamesjames1"
strComputer = objInFile.Readline
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if instr (strComputer, "localhost") then
Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", ms406)
Set objSWbemServices1 = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", ms406)
else
Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", "james", "jamesjames1", ms406)
end if
'
objSWbemServices.Security_.authenticationLevel = 6
Set colitems = objSWbemServices.ExecQuery("Select * From virtualdirectory")
Set colitems1 = objSWbemServices1.ExecQuery("Select * From application")
' inputbox which creates the backup folder if its not already there
'backupdir1=InputBox("Backup Folder Path:","Backup Folder")
backupdir1 = "C:\jamesIIS\"
datedir = replace(date,"/","_")
wscript.echo datedir
if not exist then
backupdir = backupdir1 & datedir
objfso.Createfolder(backupdir)
else
end if
for each objapp in colitems1
arrMem1 = array(objapp.applicationpool)
for i = 0 to UBound(arrMem1)
wscript.echo arrmem1(j)
next
for each objapp1 in colitems
arrMem3 = array(objapp1.physicalpath)
for i = 0 to UBound(arrMem3)
wscript.echo arrmem3(i)
next
for each objapp2 in colitems1
arrMem4= array(objapp2.sitename)
for i = 0 to UBound(arrMem4)
wscript.echo arrmem4(k)
next
next
next
next
loop
For the site and oath name I am using 'Select & from application'
Set colitems1 = objSWbemServices1.ExecQuery("Select * From application"
For the path and sitename I am using 'select * from virtualdirectory'
The script works but its coming out in the wrong order so the site name appears to have the incorrect application pool.
Does anyone know a way to either do this so that each application pool, site and path comes in the correct order?
Thanks
James
I have a script which pulls from IIS7 the application path, the application pool and the site name. The apppool comes from a different part of the WMI database so needs a different object to connect. Here is my code:
Const strInFile = "hostlist.txt"
Const ForReading = 1
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objInFile, objOutFile
Set objInFile = objFSO.OpenTextFile(strInFile,ForReading, False)
Do Until objInFile.AtEndOfStream
strUser = "james"
strpassword= "jamesjames1"
strComputer = objInFile.Readline
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if instr (strComputer, "localhost") then
Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", ms406)
Set objSWbemServices1 = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", ms406)
else
Set objSWbemServices = objSWbemLocator.ConnectServer (strComputer, "root\WebAdministration", "james", "jamesjames1", ms406)
end if
'
objSWbemServices.Security_.authenticationLevel = 6
Set colitems = objSWbemServices.ExecQuery("Select * From virtualdirectory")
Set colitems1 = objSWbemServices1.ExecQuery("Select * From application")
' inputbox which creates the backup folder if its not already there
'backupdir1=InputBox("Backup Folder Path:","Backup Folder")
backupdir1 = "C:\jamesIIS\"
datedir = replace(date,"/","_")
wscript.echo datedir
if not exist then
backupdir = backupdir1 & datedir
objfso.Createfolder(backupdir)
else
end if
for each objapp in colitems1
arrMem1 = array(objapp.applicationpool)
for i = 0 to UBound(arrMem1)
wscript.echo arrmem1(j)
next
for each objapp1 in colitems
arrMem3 = array(objapp1.physicalpath)
for i = 0 to UBound(arrMem3)
wscript.echo arrmem3(i)
next
for each objapp2 in colitems1
arrMem4= array(objapp2.sitename)
for i = 0 to UBound(arrMem4)
wscript.echo arrmem4(k)
next
next
next
next
loop
For the site and oath name I am using 'Select & from application'
Set colitems1 = objSWbemServices1.ExecQuery("Select * From application"
For the path and sitename I am using 'select * from virtualdirectory'
The script works but its coming out in the wrong order so the site name appears to have the incorrect application pool.
Does anyone know a way to either do this so that each application pool, site and path comes in the correct order?
Thanks
James