Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Param
(
[Parameter(Mandatory=$true)]
[string]$VirtualNetworkName,
[Parameter(Mandatory=$false)]
[string]$SubnetName = '',
[Parameter(Mandatory=$true)]
[string]$Location,
[Parameter(Mandatory=$true)]
[string]$ResourceGroupName
)
Begin
{
$ResourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
$VirtualNetwork = Get-AzureRmVirtualNetwork -Name $VirtualNetworkName -ResourceGroupName $ResourceGroup.ResourceGroupName
}
Process
{
foreach ($SubnetConfig in (Get-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $VirtualNetwork))
{
if ($SubnetConfig.IpConfigurations)
{
foreach ($IpConfiguration in $SubnetConfig.IpConfigurations)
{
if ($IpConfiguration.Id.Contains('loadBalancers'))
{
$LoadBalancer = Get-AzureRmLoadBalancer -Name $IpConfiguration.Id.Split('/')[8] -ResourceGroupName $IpConfiguration.Id.Split('/')[4]
New-Object -TypeName psobject -Property @{
Name = ($LoadBalancer.Name)
Type = 'LoadBalancer'
PrivateIpAddress = ($LoadBalancer.FrontendIpConfigurations |ForEach-Object {$_.PrivateIpAddress})
}
}
else
{
$NetworkInterfaceName = $IpConfiguration.Id.Split('/')[8]
$NetworkInterfaceResourceGroupName = $IpConfiguration.Id.Split('/')[4]
$NetworkInterface = Get-AzureRmNetworkInterface -Name $NetworkInterfaceName -ResourceGroupName $NetworkInterfaceResourceGroupName
New-Object -TypeName psobject -Property @{
Name = ($NetworkInterface.VirtualMachine.Id.Split('/')[8])
Type = 'VirtualMachine'
PrivateIpAddress = ($NetworkInterface.IpConfigurations |ForEach-Object {$_.PrivateIpAddress})
}
}
}
}
else
{
}
}
}
End
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.