Last active
November 30, 2015 20:47
-
-
Save jeffpatton1971/917f42a589cafbf1a5e5 to your computer and use it in GitHub Desktop.
This script will return the assigned private ips of each machine in a given subnet. If no subnet is provided it will return the assigned private ips for every machine in all subnets with a configuration.
This file contains hidden or 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