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 ffdfd
• 5,550 points
1,532 views

1 answer to this question.

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,890 points

Related Questions In DevOps on Cloud

0 votes
1 answer
0 votes
2 answers
0 votes
0 answers

Prevent users from editing master branch in ADF

In ADF, I'm attempting to prevent dev ...READ MORE

Dec 20, 2022 in DevOps on Cloud by Damonlang
• 1,230 points
199 views
+3 votes
2 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,460 views
+2 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,220 points
4,434 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP