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,530 points
225 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,810 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,280 points
502 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
152 views
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,110 points
595 views