I want to get azure VM name from IP address, I tried following to get NIC name from IP and find to which VM that NIC is attached.
Get-AzureRmNetworkInterface | ForEach { $Interface = $_.Name; $IPs = $_ | Get-AzureRmNetworkInterfaceIpConfig | Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress }
Is there a better way to get VM name directly using VM private ?
Is there a better way to get VM name directly using VM private ?
Do you mean use VM's private IP address to get the VM's name? If I understand it correctly, we can use this PowerShell to get the VM's name:
PS C:> get-azurermvm
ResourceGroupName Name Location VmSize OsType NIC ProvisioningState
----------------- ---- -------- ------ ------ --- -----------------
RGNAME jason eastus Standard_A1 Linux jason66 Succeeded
PS C:\> $a = ((Get-AzureRmNetworkInterface | ?{$_.IpConfigurations.PrivateIpAddress -eq '10.0.0.4'}).VirtualMachine).ID
PS C:\> $vmname = ($a -split '/') | select -Last 1
PS C:\> $vmname
jason
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With