Fetch AzureVm name from private IP in powershell

0 votes

How can I fetch AzureVM name from IP address. I have already tried to get NIC name from IP by doing the following.

Get-AzureRmNetworkInterface | ForEach { $Interface = $_.Name; $IPs = $_ | Get-AzureRmNetworkInterfaceIpConfig | Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress }

Can this be done in a better way?

Jul 17, 2018 in DevOps on Cloud by Atul
• 5,470 points
106 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

If by a better way you mean using VM's private IP to get it's name then you can use the following powershell to get VM's name:

PS C:> get-azurermvm

ResourceGroupName  Name Location      VmSize OsType     NIC ProvisioningState
-----------------  ---- --------      ------ ------     --- -----------------
RGNAME            Kylie   eastus Standard_A1  Linux Kylie69         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
Kylie
answered Jul 17, 2018 by DareDev
• 6,520 points

Related Questions In DevOps on Cloud

0 votes
1 answer
0 votes
2 answers
+3 votes
2 answers
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,000 points
292 views
+13 votes
2 answers
0 votes
1 answer
+2 votes
2 answers
+4 votes
2 answers

unable to get subdomain of URL in NGINX

You just need to add .+ after ...READ MORE

answered Oct 11, 2018 in DevOps on Cloud by lina
• 8,100 points
447 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.