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 |
You could do something like this
$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
You could do something like this
$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
Thank you LucD. That worked