Hi all,
I can get the network names of a VM.
(get-vm -name My-VM-Name).NetworkAdapters
I can get the IP adresses from a guest.
(Get-VMGuest -VM My-VM-Name).ipaddress
But when I try to get both they don't match up. The IP does not belong to the named network. They don't appear to be stored the same in there internal arrays. Is there a relationship defined somewhere to get these together so I can list the IPs assigned and the network names they are on?
Thx!
Provided the guest is running and you have VMware tools installed, you can do something like this:
Get-VM | %{ Write-Host $_.Name foreach($nic in $_.Guest.Nics){ Write-Host $nic.NetworkName $nic.IPAddress } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Provided the guest is running and you have VMware tools installed, you can do something like this:
Get-VM | %{ Write-Host $_.Name foreach($nic in $_.Guest.Nics){ Write-Host $nic.NetworkName $nic.IPAddress } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a ton!
That whole object.object.object.property notation is rather new to me.
I can see it is very powerful though.
Ciao
That line doesnt work for me (unexpected token 'in' in expression or statement...)
I think you need to include a semi-colon before the foreach statement, i.e.:
Get-VM | %{ Write-Host $_.Name; foreach($nic in $_.Guest.Nics){ Write-Host $nic.NetworkName $nic.IPAddress } }
Thanks!
That's probably because you think it was a one-liner.
It was not, the sample script contained multiple lines.
That is a known issue with IE and the forum SW
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah WOW ! Switched to Firefox and all becomes clear, I see your line breaks now.
Many thanks LucD.
Hello... What is the issue with IE and the forum? How would I need to type in your above script to get it to work? Thanks
Hello... What is the issue with IE and the forum?
In order to get syntax highlighting and (some) protection from code being mangled by the wiki-formatting nature of this forum software, you can use the and tags in your posts. (You remove the spaces between the words and the braces in order for it to work.) It works great when viewed from FF, but not so well from IE or Chrome. I have been informed that this will be resolved in a forum upgrade to happen in November.
How would I need to type in your above script to get it to work?
View it in FF to see the proper line-breaks, or ask for it to be saved as an attachment or posted elsewhere (such as pastebin.com). Hopefully this problem will go away next month.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
The other workaround is to reply to the message and quote it (press the quote icon to bring the parent message in). For whatever reason it will render properly then.