In part 1 I demonstrated how to read the contents of a DE xml file into Powershell and how to begin to explore it. I'll continue on that theme.
I imported the XML content of BORN_TO_FAIL into a Powershell XML variable and showed how you can find all the NT jobs by typing in $xmlData.appl.nt_job, or how you can look at a specific NT job by referencing it's position in the index (ex. $xmlData.appl.nt_job[1]).
Now lets look at using .Childnodes. You may not want to look for specific nodes like nt_job. You may just want to be more broad. For this you can ask Powershell to show you all child nodes within the appl node, or more specifically the name of all the child nodes. Entering $xmlData.appl.Childnodes.name produces the following:
PS C:\Users\AR15926> $xmlData.appl.ChildNodes.name
appl_runtime_name
version
comment
applopts
on_run
defaults
job_templates
BORN_TO_FAIL
BORN_TO_FAIL
BORN_TO_FAIL
The first 6-10 nodes are all application specific, depending on what application level options you have enabled. All the subsequent nodes are the work objects (jobs. links. externals, etc) you would see if you looked at the application in the client.
In the case of BORN_TO_FAIL, one way to look at the jobs alone would be to ask for all the child nodes starting from index 7 to the last index. This is accomplished with the following:
$xmlData.appl.ChildNodes[7..$xmldata.appl.ChildNodes.Count].name
The results are my 3 nt jobs, but this method would list any work object by its name. Having narrowed down the array to just work objects, now lets try putting a few things together to produce something useful.
[xml]$xmlData = Get-Content -Path 'D:\xml\BORN_TO_FAIL'
$wobs= $xmlData.appl.ChildNodes[7..$xmldata.appl.ChildNodes.Count]
ForEach ($wob in $wobs) {Write-Host $wob.name $wob.qualifier $wob.agent $wob.userid $wob.cmdname}
With this you get a list of every Work Object in this application with its qualifier, agent, user, cmd name, assuming the work object has those fields.
BORN_TO_FAIL 1 FAKE_AGENT01 FAKE_USER01 D:\Cyb_exec\andy_test\born_to_fail.bat
BORN_TO_FAIL 2 FAKE_AGENT01 FAKE_USER01 D:\Cyb_exec\andy_test\DOA.bat
BORN_TO_FAIL 3 FAKE_AGENT01 FAKE_USER01 D:\Cyb_exec\andy_test\NO_CHANCE.bat
Now instead of looking at one xml file, we can use Get-ChildItem to look at an entire folder of exported xml files and pipe them to a ForEach-Object command.
Get-ChildItem -Path D:\XML\ | ForEach-Object {
[xml]$xmlData = Get-Content $_.FullName
write-host "------------------"$xmlData.appl.name"------------------------------"
$wobs= $xmlData.appl.ChildNodes[7..$xmldata.appl.ChildNodes.Count]
ForEach ($wob in $wobs) {Write-Host $wob.name $wob.qualifier $wob.agent $wob.userid $wob.cmdname}
}
Instead of writing this out to the screen with the write-host command, you can use out-csv to put this information into a csv file.
I still haven't got into the use of XPath to locate nodes. I guess there will be a part 3, but for now I have to go fix my kitchen stove and get outside with my kids.
------------------------------
Andy Reimer
------------------------------