How to get public IP address of Azure VM using PowerShell

In this Azure PowerShell article, we will discuss how to get the Public IP of Azure Virtual Machine using Azure PowerShell.

How to get public IP address of Azure VM using PowerShell

Well, you can easily use Azure PowerShell to retrieve the Public IP address of your Azure Virtual machine within seconds.

When you need to retrieve all the properties of your Virtual machine, including its name, Resource Group name, Location, ID, and Public IP address, you can simply execute the Azure PowerShell cmdlet below.

Get-AzPublicIpAddress -ResourceGroupName Resource Group Name | Where-Object {$_.name -like "*Virtual Machine Name*" }

Example: You can retrieve all the details of the TsInfoVM1 and get Azure VM IP address using Powershell, which belongs to the Demo123 Resource Group.

Get-AzPublicIpAddress -ResourceGroupName Demo123 | Where-Object {$_.name -like "*TsInfoVM1*" }

Once I executed the Azure PowerShell cmdlet, I got the output below.

Name                     : TsInfoVM1-ip
ResourceGroupName        : Demo123
Location                 : eastus
Id                       : /subscriptions/1cdf4300-1233-4518-9c9c-feaa72a5cbd1/resourc
                           eGroups/Demo123/providers/Microsoft.Network/publicIPAddress
                           es/TsInfoVM1-ip
Etag                     : W/"2aaebff2-1c21-47ba-8750-9db7cd548c9a"
ResourceGuid             : 0d81f214-43dc-4612-938c-353cae02a798
ProvisioningState        : Succeeded
Tags                     : 
PublicIpAllocationMethod : Dynamic
IpAddress                : 20.228.214.47
PublicIpAddressVersion   : IPv4
IdleTimeoutInMinutes     : 4
IpConfiguration          : {
                             "Id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd
                           1/resourceGroups/Demo123/providers/Microsoft.Network/networ
                           kInterfaces/tsinfovm1353/ipConfigurations/ipconfig1"
                           }
DnsSettings              : null
Zones                    : {}
Sku                      : {
                             "Name": "Basic",
                             "Tier": "Regional"
                           }
IpTags                   : []

You can see it here

How to get public IP address of Azure VM using PowerShell

Now, if you want to retrieve only the Public IP address of your Azure Virtual Machine, you can use the Azure PowerShell cmdlet below.

Retrieve only the Public IP address of your Azure Virtual Machine

Get-AzPublicIpAddress -ResourceGroupName Resource Group Name | Where-Object {$_.name -like "Virtual Machine Name" } | Select-Object { $_.IpAddress }

As an example below, the Azure PowerShell cmdlet will retrieve only the Public IP address of the TsInfoVM1 virtual machine that belongs to the Demo123 Resource Group.

Get-AzPublicIpAddress -ResourceGroupName Demo123 | Where-Object {$_.name -like "TsInfoVM1" } | Select-Object { $_.IpAddress }

Once you execute the above cmdlet, you will get the output below.

$_.IpAddress 
--------------
20.228.214.47 

You can see it below.

get-azvm ip address

Get-AzPublicIpAddress

Get-AzPublicIpAddress is an excellent Azure PowerShell cmdlet to retrieve one or multiple Public IP addresses of the resources in a Resource Group.

Syntax: Below is the simple syntax of the Get-AzPublicIpAddress Azure PowerShell cmdlet.

Get-AzPublicIpAddress
 [-Name <String>]
[-ResourceGroupName <String>]
 [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]
Get-AzPublicIpAddress -Name resource name -ResourceGroupName Resource group name
Get-AzPublicIpAddress -Name resource name*

For Example, The below Azure PowerShell cmdlet will retrieve most of the properties along with the Public IP addresses of the TsInfoVM1 under the Demo123 resource group.

Get-AzPublicIpAddress -Name TsInfoVM1-ip -ResourceGroupName Demo123

After running the above cmdlet, I got the output as below.

Get-AzPublicIpAddress

Or, you can also execute the cmdlet with filter conditions like below

Get-AzPublicIpAddress -Name TsInfoVM1*

If you execute the above cmdlet, you will get the output like the above.

Name                     : TsInfoVM1-ip
ResourceGroupName        : Demo123
Location                 : eastus
Id                       : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourc
                           eGroups/Demo123/providers/Microsoft.Network/publicIPAddress
                           es/TsInfoVM1-ip
Etag                     : W/"f34fc0fa-8eb9-449e-bd15-ecf7ab04abb0"
ResourceGuid             : 0d81f214-43dc-4612-938c-353cae02a798
ProvisioningState        : Succeeded
Tags                     : 
PublicIpAllocationMethod : Dynamic
IpAddress                : 20.127.76.41
PublicIpAddressVersion   : IPv4
IdleTimeoutInMinutes     : 4
IpConfiguration          : {
                             "Id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd
                           1/resourceGroups/Demo123/providers/Microsoft.Network/networ
                           kInterfaces/tsinfovm1353/ipConfigurations/ipconfig1"
                           }
DnsSettings              : null
Zones                    : {}
Sku                      : {
                             "Name": "Basic",
                             "Tier": "Regional"
                           }
IpTags                   : []

You may also like the following articles below

Wrapping Up

Well, in this article, we have discussed how to retrieve the Public IP of Azure Virtual Machine using Azure PowerShell.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!