So I wrote a powershell script to read in an xml file, parse through it, and output to a file after its been cleaned up. My issue is that as it loops through the foreach loop it is storing it all to the same variables.
#Access the XML file
[xml]$XML= [xml](Get-Content $XmlPath)
foreach ($node in $XML.catalog.entry)
{
#XML Variables
$Username = $XML.catalog.entry.username
$Description = $XML.catalog.entry.description
$Service = $XML.catalog.entry.service
#Creating the syslog event that will be sent to SecureVue
$writeOutput= "Username : [$Username] Description: [$Description] Service: [$Service]"
#output
$writeOutput
}
Unfortunately, the output I keep getting it:
Username : [User1 User2 User3 User4] Description: [Description1 Description2 Description3 Description4] Service: [Service1 Service2 Service3 Service4]
Username : [User1 User2 User3 User4] Description: [Description1 Description2 Description3 Description4] Service: [Service1 Service2 Service3 Service4]
Username : [User1 User2 User3 User4] Description: [Description1 Description2 Description3 Description4] Service: [Service1 Service2 Service3 Service4]
Username : [User1 User2 User3 User4] Description: [Description1 Description2 Description3 Description4] Service: [Service1 Service2 Service3 Service4]
Instead of:
Username : [User1] Description: [Description1] Service: [Service1]
Username : [User2] Description: [Description2] Service: [Service2]
Username : [User3] Description: [Description3] Service: [Service3]
Username : [User4] Description: [Description4] Service: [Service4]
I know i need some variation of:
foreach($node in $XML.ChildNodes)
But I can't seem to get it to work. Any ideas on how to write out each line with the one array position for each node in the array?
Thank you!