Skip to content

Instantly share code, notes, and snippets.

@eosfor
Last active May 24, 2022 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eosfor/8ecaae4ba6e5e0b4c4ed64294a117519 to your computer and use it in GitHub Desktop.
Save eosfor/8ecaae4ba6e5e0b4c4ed64294a117519 to your computer and use it in GitHub Desktop.
$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