Option Explicit
Const STSADM_PATH ="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm"
Const ROOT_URL = "http://pravmoss/"
Const FILE_NAME = "D:\listofsites.xml"
Dim objShell, objExec, objXml, objXml2,objXml3, objSc,objFso, objFile, objWeb
Dim strResult, strSubResult, strUrl, strCmd, strOwner, strXML
'Retrieves all site collections in XML format.
WScript.Echo "Creating shell object and calling root enumsites command"
Set objShell = CreateObject("WScript.Shell")Set objExec = objShell.Exec(STSADM_PATH & " -o enumsites -url " & ROOT_URL)
strResult = objExec.StdOut.ReadAll
'Load XML in DOM document so it can be processed.
WScript.Echo "Loading XML File"
Set objXml = CreateObject("MSXML2.DOMDocument")Set objXml2 = CreateObject("MSXML2.DOMDocument")Set objXml3 = CreateObject("MSXML2.DOMDocument")
objXml.LoadXML(strResult)
WScript.Echo "Creating File System Object"
'Create the FileSystemObject and write to file.
Set objFso = CreateObject("Scripting.FileSystemObject")
if objFso.FileExists(FILE_NAME) then
objFso.DeleteFile FILE_NAME, True
end if
set objFile = objFso.CreateTextFile(FILE_NAME, True)
'Loop through each site collection and call enumsubwebs to get the child URL's.
objFile.WriteLine("<ROOT>")For Each objSc in objXml.DocumentElement.ChildNodes
strUrl = objSc.Attributes.GetNamedItem("Url").Text strOwner = objSc.Attributes.GetNamedItem("Owner").Text strCmd = STSADM_PATH & " -o enumsubwebs -url """ + strUrl + """"
Set objExec = objShell.Exec(strCmd)
strResult = objExec.StdOut.ReadAll
objFile.WriteLine("<SITECOLLECTION SiteCollectionURL='" & strUrl & "' Owner = '" & strOwner & "'>") objFile.WriteLine(strResult)
WScript.Echo "Traversing the sub Webs..."
call GetSubSites(strResult)
objFile.WriteLine("</SITECOLLECTION>")
Next
objFile.WriteLine("</ROOT>")
set objFile = nothing
set objFso = nothing
set objXml = nothing
set objXml2 = nothing
set objXml3 = nothing
set objExec = nothing
WScript.Echo "File created"
sub GetSubSites(strResult)
objXml2.LoadXML(strResult)
for Each objWeb in objXml2.DocumentElement.ChildNodes
strCmd = STSADM_PATH & " -o enumsubwebs -url """ + objWeb.text + """"
Set objExec = objShell.Exec(strCmd)
strResult = objExec.StdOut.ReadAll
objXml3.LoadXML(strResult)
if objXml3.DocumentElement.Attributes.GetNamedItem("Count").Text <> "0" Then objFile.WriteLine(strResult)
WScript.Echo strResult
call GetSubSites(strResult)
end if
next
end sub