Created
August 1, 2016 21:51
-
-
Save jeffpatton1971/d20571e232168c2796285715c6b1d126 to your computer and use it in GitHub Desktop.
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
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