penfold Posted February 8, 2019 Posted February 8, 2019 I'm trying to check all the exclusinos we have in McAfee and I'd like to export them into csv so I can compare what they acually are with what they are supposed to be. I have exported some settings which can only be done into xml file but I am trying to get it into a readable (csv or other) format. The structure is as follows: . . . . . What I want to be able to do is pull out the values for the ExcludedItems after the Section name "Server_Default-Exclusions". I have been able to read the file using $XmlDocument = Get-Content -Path $Path but what I can't seem to do is select the correct section. I've tried $XmlDocument.SelectNodes but I just don't know how to get to the correct section name and pull out all the settings within that section. Is this possible - or even an easier way to do this?
Arthur Posted February 8, 2019 Posted February 8, 2019 This might do what you want... [xml]$XmlDocument = @" <[color="#FF0000"]Section[/color]> <[color="#0000CD"]Section[/color] name="Server_Default-Exclusions"> <[color="#EE82EE"]Setting[/color] name="ExcludedItem_0" [color="#FF0000"]value[/color]="exclusion1" /> <[color="#EE82EE"]Setting[/color] name="ExcludedItem_1" [color="#FF0000"]value[/color]="exclusion2" /> "@ $XmlDocument.[color="#FF0000"]Section[/color].[color="#0000CD"]Section[/color].[color="#EE82EE"]Setting[/color] | Select-Object -ExpandProperty [color="#FF0000"]Value[/color] 1
HPlum78 Posted February 8, 2019 Posted February 8, 2019 Select-Xml -Xml $XmlDocument -XPath "//Section" | foreach {$_.Node.ChildNodes} | export-csv /Users/h/Documents/PowerShell/xml_csv_Expt.csv 1
penfold Posted February 11, 2019 Author Posted February 11, 2019 @HPlum78 - Thanks I think I can get everything I need with that.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now