Reputation: 315
Trying to figure out how to read an XML file from public blob storage.
When I have the XML in my powershell script, I was able to reference it like so:
[xml]$xml = @"
<?xml version="1.0"?>
<PublicSubnets>
<Subnet>1.2.3.0/24</Subnet>
<Subnet>2.3.4.0/24</Subnet>
<Subnet>192.168.1.0/24</Subnet>
<Subnet>10.0.0.0/8</Subnet>
</PublicSubnets>
"@
foreach ($subnet in $xml.PublicSubnets.Subnet)
{
$subnet
}
This would print the four subnets.
I'm trying to get that XML into a separate XML document, that's stored in public blob storage. Example: https://teststorage.blob.core.windows.net/automation/Subnet.xml
So basically looking for the same functionality I had with the XML included in the script, but looking for the XML to be hosted externally (I removed the first and last line of the XML - "[xml]$xml = @"" and ""@"
Upvotes: 0
Views: 891
Reputation: 142
Generate a SAS token for the blob and grab the URI and SAS token and put them into the variables $XmlBlobUrl (The Uri of the XML Blob) and $SASToken (Query string of the SAS token)
$XmlBlobUrl = "https://BlobStorageAccount.blob.core.windows.net/subnets.xml"
$SASToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$Url = $XmlBlobUrl + $SASToken
$Subnets = @()
[xml]$xml = Invoke-WebRequest $Url | Select-Object -Expand Content
foreach ($subnet in $xml.PublicSubnets.Subnet) {
$Subnets += $Subnet
}
$Subnets
Upvotes: 0