I'm trying to write a PowerShell script that lists me all connected devices with there ips in my subnets in all VNets in all subscriptions.
UPDATE the below script works, scroll down for original problem.
$subs = Get-AzSubscription
foreach ($Sub in $Subs) {
Write-Host "***************************"
Write-Host " "
$Sub.Name
$SelectSub = Select-AzSubscription -SubscriptionName $Sub.Name
$VNETs = Get-AzVirtualNetwork
foreach ($VNET in $VNETs) {
Write-Host "--------------------------"
Write-Host " "
Write-Host " vNet: " $VNET.Name
Write-Host " AddressPrefixes: " ($VNET).AddressSpace.AddressPrefixes
$vNetExpanded = Get-AzVirtualNetwork -Name $VNET.Name -ResourceGroupName $VNET.ResourceGroupName -ExpandResource 'subnets/ipConfigurations'
foreach($subnet in $vNetExpanded.Subnets)
{
Write-Host " Subnet: " $subnet.Name
Write-Host " Connected devices " $subnet.IpConfigurations.Count
foreach($ipConfig in $subnet.IpConfigurations)
{
Write-Host " " $ipConfig.PrivateIpAddress
}
}
Write-Host " "
}
}
My original problem:
The problem however is that I cannot get the $subnet.IpConfigurations property to be filled. By that I mean that I do get a list but the child items only contain an Id, the rest of the properties like name, privateip, etc are null.