Last active
May 24, 2022 01:51
-
-
Save eosfor/8ecaae4ba6e5e0b4c4ed64294a117519 to your computer and use it in GitHub Desktop.
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
$vm = Get-AzVM -Status | % { Add-Member -InputObject $_ -Name "NICObj" -MemberType NoteProperty -Value (Get-AzNetworkInterface -ResourceId $_.NetworkProfile.NetworkInterfaces[0].id) -Force -PassThru } | | |
% { Add-Member -InputObject $_ -Name "PrivateIP" -MemberType NoteProperty -Value ($_.NICObj.IpConfigurations[0].PrivateIpAddress) -Force -PassThru} | | |
% { if ($_.NICObj.IpConfigurations[0].PublicIpAddress.count -gt 0) { | |
$rIdparsed = $_.NICObj.IpConfigurations[0].PublicIpAddress[0].Id -split "/"; | |
Add-Member -InputObject $_ -Name "PublicIP" -MemberType NoteProperty -Value ((Get-AzPublicIpAddress -Name $rIdparsed[-1] -ResourceGroupName $rIdparsed[4]).IpAddress) -Force -PassThru | |
} | |
else { | |
$_ | |
} | |
} | | |
% {Add-Member -InputObject $_ -Name "VNET" -MemberType NoteProperty -Value (($_.NICObj.IpConfigurations[0].Subnet.id -split "/")[8]) -Force -PassThru} | | |
% {Add-Member -InputObject $_ -Name "Subnet" -MemberType NoteProperty -Value (($_.NICObj.IpConfigurations[0].Subnet.id -split "/")[-1]) -Force -PassThru} | | |
% {Add-Member -InputObject $_ -Name "VmSize" -MemberType NoteProperty -Value ($_.HardwareProfile.VmSize) -Force -PassThru} | | |
% {Add-Member -InputObject $_ -Name "osType" -MemberType NoteProperty -Value ($_.StorageProfile.OsDisk.OsType) -Force -PassThru} | |
$vm | ft ResourceGroupName, Name, Location, VmSize, osType, VNET, Subnet, PrivateIP, PublicIP -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment