VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get-VM IP Address in different Columns

Hi,

I have VMs with multiple IP Address and How can I get the IP-Address of the VMs in different Columns

Please help!!!

Script:

get-vm | Select Name, @{N="IP Address";E={($_.guest.IPAddress)-join ", "}}

Output

Name     IP Address

Demo1     192.168.1.100, 192.168.1.101

Demo2   192.168.1.109, 192.168.1.110

I want output similar to

Name        IP Address       IP Address1

Demo1     192.168.1.100 192.168.1.101

Demo2 192.168.1.109 192.168.1.110
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$result = @()

$vms = Get-VM

$maxIP = ($vms.Guest | %{$_.IPAddress.Count} | Measure-Object -Maximum).Maximum


$vms | ForEach-Object -Process {

    $obj = [ordered]@{

        VM = $_.Name

    }

    1..$maxIP | %{

        $obj.Add("IP$($_)",'')

    }


    $i = 1

    $_.Guest.IPAddress | ForEach-Object -Process {

        $obj.Item("IP$($i)") = $_

        $i++

    }

    $result += New-Object -TypeName PSObject -Property $obj

}

$result


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$result = @()

$vms = Get-VM

$maxIP = ($vms.Guest | %{$_.IPAddress.Count} | Measure-Object -Maximum).Maximum


$vms | ForEach-Object -Process {

    $obj = [ordered]@{

        VM = $_.Name

    }

    1..$maxIP | %{

        $obj.Add("IP$($_)",'')

    }


    $i = 1

    $_.Guest.IPAddress | ForEach-Object -Process {

        $obj.Item("IP$($i)") = $_

        $i++

    }

    $result += New-Object -TypeName PSObject -Property $obj

}

$result


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD. That worked Smiley Happy

Reply
0 Kudos