I have an Azure powershell script that's pulling an XML file and then running the values through a 'foreach' loop.
I have a blob file in Azure storage with the following format (XML) -
<?xml version="1.0"?>
<Root>
<PublicSubnets>
<Subnet>192.168.1.0/24</Subnet>
<Subnet>192.168.50.0/24</Subnet>
<Subnet>10.82.19.5/24</Subnet>
<Subnet>10.1.1.0/16</Subnet>
<Subnet>172.16.15.0/16</Subnet>
</PublicSubnets>
<Descrip>
<Description>"This is the description"</Description>
</Descrip>
</Root>
The idea is for an azure powershell script to loop through the XML and create a network security group entry for each of them. That part works just fine.
What i'm trying to do is instead of ingesting a XML file, I want it to be a Json with all the subnet values.
Here's the current script (note that $nsgname and $resourcegroupname are entered by the user, for a network security group that the script will then create NSG entries for each subnet in the XML file)
$Url = "https://theteststorage.blob.core.windows.net/params/SubnetParams.xml?st=2018-10-25T19andrestoftheURL"
$Subnets = @()
[xml]$xml = Invoke-WebRequest $Url -UseBasicParsing | Select-Object -Expand Content
$counter=0
foreach ($subnet in $xml.Root.PublicSubnets.Subnet)
{
$counter++
Write-Output "Counter is at $counter and subnet is $subnet"
}
This should print out: Counter is at 1 and subnet is 192.168.1.0/24 Counter is at 2 and subnet is 192.168.50.0/24
How would I go about doing that but instead of XML, it would be Json