Last active
May 18, 2022 15:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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