Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- {
- $NetworkInterfaceName = $IpConfiguration.Id.Split('/')[8]
- $NetworkInterfaceResourceGroupName = $IpConfiguration.Id.Split('/')[4]
- $NetworkInterface = Get-AzureRmNetworkInterface -Name $NetworkInterfaceName -ResourceGroupName $NetworkInterfaceResourceGroupName
- New-Object -TypeName psobject -Property @{
- VirtualMachineName = ($NetworkInterface.VirtualMachine.Id.Split('/')[8])
- PrivateIpAddress = ($NetworkInterface.IpConfigurations |ForEach-Object {$_.PrivateIpAddress})
- }
- }
- }
- else
- {
- }
- }
- }
- End
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement