Using PowerCLI to get the IP address of a VM

简介:

Here is a simple but handy PowerCLI one liner which can output the VM name and it's IP address.

 

Connect-VIServer localhost
Get-VM | Select Name, @{N="IP Address";E={@($_.guest.IPAddress[0])}}

 

Name                                            IP Address
----                                            ----------
ABWEB1v                                         172.16.100.1
ABWEB2v                                         172.16.100.2
ABWEB3v                                         172.16.100.3
ABWEB4v                                         172.16.100.4
ABWEB5v                                         172.16.100.5
ABWEB6v                                         172.16.100.6
ABWEB7v                                         172.16.100.7
ABWEB8v                                         172.16.100.8
ABWEB9v                                         172.16.100.9
ABWEB10v                                        172.16.100.10
ABWEB11v                                        172.16.100.11
ABAPP1v                                         172.16.101.20
ABDOM1v                                         172.16.102.20

 

Getting a little more complicated here we are getting all the VMs in any cluster starting with "Web-Cluster-" and then returning the VM Name, ESXi host and IP address:

Get-Cluster "Web-Cluster-*" | Get-VM | Select Name, Host, @{N="IP Address";E={@($_.guest.IPAddress[0])}}

 

Due to the way the IP address is referenced and a VM can have more than one IP, you can list additional IPs by adding or changing the array pointer from 0 to 1 and so on, in this part of the command "$_.guest.IPAddress[1]"

本文转自学海无涯博客51CTO博客,原文链接http://blog.51cto.com/549687/1842533如需转载请自行联系原作者

520feng2007
相关文章
|
Ubuntu 虚拟化
VMware 虚拟机 Ubuntu 系统执行 ifconfig 命令 eth0没有IP地址(intet addr、Bcast、Mask)
VMware 虚拟机 Ubuntu 系统执行 ifconfig 命令 eth0没有IP地址(intet addr、Bcast、Mask)
437 0
|
开发工具
Mac修改主机host地址
Mac修改主机host地址
223 0
|
网络安全 网络虚拟化 网络架构
openstack 指定创建 vm IP 地址
当前使用 vlan 网络架构 默认状态下创建 VM 利用 DHCP 进行 IP 地址分配 由于某些原因需要指定某些 VM 的 IP 地址, 那么可以参考下面方法执行操作 先获得  TENANT,  NETWORK 信息,  然后创建对应的 PORT,  PORT 可以指定使用某个 IP 地址,  之后在创建 VM 时候指定对应的 PORT就可以 获得 tenant id
1619 0
|
Linux
linux永久更改eth0的ip地址后仍然ping不通过
编辑文件/etc/sysconfig/network-scripts/ifcfg-eth0 引用:DEVICE=eth0 //设备名称,不要修改 BOOTPROTO=static //不要修改 BROADCAST=10.
956 0

热门文章

最新文章