Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Last active May 18, 2022 15:50
Show Gist options
  • Save JohnL4/1e5d8037d23e1f19cbfda84f5da2ceb6 to your computer and use it in GitHub Desktop.
Save JohnL4/1e5d8037d23e1f19cbfda84f5da2ceb6 to your computer and use it in GitHub Desktop.
Extract data from multiple XML files, composing into PSCustomObjects which can then be sorted uniquely.
# ls *.xml | % {[xml] $xml = cat $_; $xml.Cloud["Cloud.Tabls"].Tables.CloudTable | % { [PSCustomObject] @{ Server = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Server; Database = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Database}}}
ls .\*.xml `
| % {[xml] $xml = cat $_; # Cast to [xml] magically parses XML text into an XmlElement (document).
# $xml | gm # Then you just have to navigate the various children and attributes.
$xml.Cloud["Cloud.Tables"].Tables.CloudTable `
| % {
# $_ | gm
[PSCustomObject] @{ # Cast to [PSCustomObject] "magically" turns a hash into an object w/hash key-value pairs as properties.
Server = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Server;
Database = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Database
}
}
} | sort Server,Database -uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment