0

I am running a Powershell command to extract an IP from a Azure container group (ACI)

my output contains the data like this (access lines have been removed)

DnsConfigNameServer            :
DnsConfigOption                :
DnsConfigSearchDomain          :
EncryptionPropertyKeyName      :
IPAddressDnsNameLabel          :
IPAddressFqdn                  :
IPAddressIP                    : 10.131.1.4
IPAddressPort                  : {{

----

By running the below command I have managed to get the IP address from the output. However, the command result provides the whole line.

Get-AzContainerGroup -Name test-aci-01 -ResourceGroupName tot-RG  | Format-List | Out-String -Stream | Select-String -Pattern "IPAddressIP"

IPAddressIP                    : 10.131.1.4

I only need the IP address. So the output should be

10.131.1.4

To simplify the question, I have stored the results in the variable.

$myipaddress=Get-AzContainerGroup -Name test-aci-01 -ResourceGroupName tot-RG  | Format-List | Out-String -Stream | Select-String -Pattern "IPAddressIP"

$myipaddress

IPAddressIP                    : 10.131.1.4

Can anyone help please?

Thanks

  • 4
    `(Get-AzContainerGroup -Name test-aci-01 -ResourceGroupName tot-RG).IPAddressIP` should likely do the trick. This is a good doc to read more about methods and properties: https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/03-discovering-objects?view=powershell-7.2 – Vish Sep 01 '22 at 13:16
  • $myipaddress=Get-AzContainerGroup -Name test-aci-01 -ResourceGroupName tot-RG | Format-List | Out-String -Stream | Select-String -Pattern "IPAddressIP" $myipaddress IPAddressIP : 10.131.1.4 – Sanjay Kumar Sep 01 '22 at 13:19
  • 3
    Yup. You don't need to convert output of a PowerShell object into a string. Output properties are accessible by "dot"-ing through them. `$myipaddress=Get-AzContainerGroup -Name test-aci-01 -ResourceGroupName tot-RG; $myipaddress.IpAddressIP` – Vish Sep 01 '22 at 13:21
  • On a general note: `Format-*` cmdlets emit output objects whose sole purpose is to provide _formatting instructions_ to PowerShell's for-display output-formatting system. In short: only ever use `Format-*` cmdlets to format data _for display_, never for subsequent _programmatic processing_ - see [this answer](https://stackoverflow.com/a/55174715/45375) for more information. – mklement0 Sep 01 '22 at 15:46

0 Answers0