Problem with XML subroutine loading file in VBScript

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im having problems with a script Ive written to parse some of the XML elements from a dump of Group Policy Objects. The script need to recurse through a large number of folders to pull the "Backup.xml" files to be parsed and Im having a bit of a problem
with that part of the logic. Im getting the error:<br/>
<br/>
C:Tempgpo2csv.vbs(56, 4) Microsoft VBScript runtime error: Invalid procedure call or argument: objXML.Load<br/>
<br/>
when I run the script. The problem seems to be in the subroutine with this line:<br/>
<br/>
gpoXML = objXML.Load(objFile)<br/>
<br/>
which I set earlier in the script. <br/>
<br/>
Any ideas?<br/>
<br/>
<pre class="prettyprint lang-vb
Declare Variables

Option Explicit

Dim objFSO
Dim objXML
Dim gpoXML
Dim nsmgr
Dim strCSV
Dim strFolder
Dim objFile
Dim nodSelect
Dim nodList
Dim nod
Dim objFolder
Dim objSubFolder
Dim objSuperFolder
Dim colFiles
Dim objGPO

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8


Configure FSO

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSuperFolder = objFSO.GetFolder(WScript.Arguments(0))


Configure XML

Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.validateOnParse = False
objXML.resolveExternals = False
objXML.setProperty "SelectionLanguage", "XPath"
objXML.setProperty "SelectionNamespaces", "xmlns:gposet=http://www.microsoft.com/GroupPolicy/Settings xmlns:gposec=http://www.microsoft.com/GroupPolicy/Types/Security xmlns:gpotyp=http://www.microsoft.com/GroupPolicy/Types"


Loop Through Folder

WScript.Echo "gpo2csv.vbs" & vbCrLf & "Syntax: gpo2csv <folder> <csv file>" & vbCrLf & "Example: gpo2csv c:/temp:/backup domain1.csv" & vbCrLf
WScript.Echo "Parsing XML files and generating CSV..." & vbCrLf
Call ShowSubFolders (objSuperFolder)

Sub ShowSubFolders(fFolder)
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If UCase(objFile.Name) = "BACKUP.XML" Then
WScript.Echo "Processing " & objFile & "..."
gpoXML = objXML.Load(objFile)
Set nodSelect = gpoXML.DocumentElement.SelectSingleNode("//gposet:Name")
Set objGPO = objFSO.OpenTextFile((1), ForWriting, True)
objGPO.Write(nodSelect.Text)
objGPO.WriteBlankLines(2)
objGPO.Close
Set objGPO = objFSO.OpenTextFile((1), ForAppending)
Set nodList = objXML.DocumentElement.SelectNodes("//gpotyp:Name")
For Each nod In nodList
objGPO.Write(nod.Text & ",")
Next
objGPO.Close
WScript.Echo "File processed..." & vbCr
Else
WScript.Echo "Bad filename, next file..." & vbCr
End If
Next

For Each objSubfolder in fFolder.SubFolders
ShowSubFolders(objSubfolder)
Next
End Sub


End Script

WScript.Echo "Finished."
WScript.Quit 0
[/code]
<br/>

View the full article
 
Back
Top